2010-03-16 15 views
6

Tôi có chế độ xem danh sách và muốn đặt nội dung cả ở trên (trên trục y) và bên dưới (trục y) bao gồm hình ảnh, chế độ xem văn bản và một hàng nút. Dưới đây là một phiên bản đơn giản của những gì tôi đang tạo ra. Thật không may là danh sách bìa (tức là trên trên trục z) các tiêu đề để văn bản tiêu đề không hiển thị thay vì bên dưới (trên trục y)Làm cách nào để đặt tiện ích con ở trên và dưới chế độ xem danh sách?

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

    <TextView android:id="@+id/footer" 
     android:text="footer" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_alignParentBottom="true" 
     /> 

    <ListView android:id="@+id/list_view" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:layout_above="@id/footer" 
     android:background="#ff9999ff"/> 

    <TextView android:id="@+id/header" 
     android:text="header" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_alignParentTop="true" 
     android:layout_above="@id/list_view" 
     android:baselineAlignBottom="false" 
     /> 

</RelativeLayout> 

Đây là lớp Hoạt động tương ứng:

public class SampleListActivity extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.list_activity); 

    } 
} 

Trả lời

9

Tôi không thể có bố cục tương đối để làm việc trong Android 1.5 nhưng tôi đã có Bố cục tuyến tính hoạt động. Dưới đây là giải pháp của tôi:

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

    <TextView android:id="@+id/header" 
     android:text="header" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_weight="0" 
     /> 
    <ListView android:id="@+id/list_view" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:background="#ff9999ff" 
     android:layout_weight="1"/> 

    <TextView android:id="@+id/footer" 
     android:text="footer" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_weight="0" 
     /> 
</LinearLayout> 
2

Nếu bạn đang nhắm mục tiêu Android 1.6 trở lên, hãy thêm android:layout_below="@id/header" vào các thuộc tính hiện tại của bạn trên ListView.

Nếu bạn vẫn đang nhắm mục tiêu Android 1.5, bạn sẽ cần phải thực hiện điều đó android:layout_below="@+id/header" và có thể xóa ký hiệu + khỏi thuộc tính android:id="@+id/header" hiện tại trong TextView.

RelativeLayout, tính đến 1.6, hỗ trợ chuyển tiếp tới các tiện ích khác, miễn là lần xuất hiện đầu tiên của giá trị ID có ký hiệu +.

5

này nên hoạt động sử dụng RelativeLayout:

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

    <TextView android:id="@+id/header" 
     android:text="header" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" /> 

    <TextView android:id="@+id/footer" 
     android:text="footer" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_alignParentBottom="true"/> 

    <ListView android:id="@id/android:list" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent" 
     android:layout_below="@id/header" 
     android:background="#ff9999ff"/> 

</RelativeLayout> 

Sửa: android loại bỏ: định hướng như đề xuất

+0

android: định hướng sai ở đây tôi nghĩ – letroll

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