2013-07-27 31 views
8

Tôi có một listview đó sẽ được lấp đầy với AsyncTask và ở rìa dưới cùng của ứng dụng tôi cần phải hiển thị một cách bố trí lớp phủ cố định như thế này:Làm thế nào để tạo ra một bố trí lớp phủ trên một listview

enter image description here

Nhưng tôi không thể tìm ra cách tôi có thể làm điều này trong xml? Đây là Layout.xml hiện tại của tôi:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <ListView 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <!-- Probably I need to do something here --> 

</LinearLayout> 
+0

http://www.curious-creature.org/2009/03/01/android-layout-tricks-3-optimize-part-1/ Hãy thực hiện điều này :) –

Trả lời

9

Như Daniel đã đề xuất, sử dụng RelativeLayout vì nó cho phép xếp chồng các thành phần (cùng với FrameLayoutSurfaceView). Đoạn mã dưới đây sẽ cung cấp cho bạn cách bố trí bạn đang tìm kiếm:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<ListView 
    android:id="@+id/list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:background="@color/transparentBlack" 
    android:layout_alignParentBottom="true" > 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/textView1" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="20dp" 
     android:text="Medium Text" 
     android:textColor="@color/white" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:layout_marginLeft="40dp" 
     android:text="Large Text" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="@color/white" /> 

    </RelativeLayout> 

</RelativeLayout> 

Trong đoạn mã trên, các giá trị hex màu sử dụng cho transparentBlack#95000000white#ffffff.

Dưới đây là hướng dẫn tuyệt vời về các khái niệm cơ bản về thiết kế giao diện người dùng trong Android: Android User Interface Design: Layout Basics.

+1

Cảm ơn nó là hoàn toàn làm việc! Tôi sẽ đọc qua liên kết bạn cung cấp :) –

+1

Điều gì sẽ xảy ra nếu bạn muốn có thể cuộn mục phía dưới cùng bên trên nút lớp phủ? – l33t

+1

@ l33t Giả sử bạn đang sử dụng một 'ArrayList' để giữ các đối tượng danh sách. Thêm một mục dấu cách 'trống' vào cuối danh sách này. Trong 'getView()' của adapter => khi (position == mArrayList.size-1), thiết lập chiều cao của 'convertView' thành' overlay's' height => thiết lập khả năng hiển thị của convertView thành 'View.INVISIBLE'. Chưa thử điều này - vì vậy phương pháp này có thể cần một số sửa đổi. Nếu bạn muốn, bạn có thể chỉnh sửa câu trả lời của tôi với việc triển khai cuối cùng của bạn. – Vikram

2

Thay đổi cách bố trí cha mẹ để RelativeLayout hoặc FrameLayout và vị trí quan điểm cố định cùng cấp của ListView (nhưng sau khi ListView) Something

như:

---> RelativeLayout 
    --> ListView 
    --> Any view as the fixed view 

Bạn có thể sau đó sắp xếp các điểm cố định để dưới cùng của gói RelativeLayout

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ListView 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <!-- Here you should position the fixed view --> 
</RelativeLayout> 
+0

Bạn có thể cho tôi một số ví dụ về mã không? –

Các vấn đề liên quan