2011-08-05 40 views
6

Tôi có một listview như sauAndroid: Footer trong một ListView

<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:background="#E6E7E2"> 
    <ImageView android:id="@+id/Thumbnail" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:src="@drawable/icon" /> 
    <TextView android:id="@+id/FilePath" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="#E6E7E2" 
     /> 
</LinearLayout> 

và tôi có chân như sau

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" android:layout_gravity="bottom"> 
    <LinearLayout android:layout_width="fill_parent" 
      android:layout_alignParentBottom="true" 
      android:layout_height="wrap_content" 
      android:id="@+id/layoutfooterbutton" android:layout_gravity="bottom"> 

      <Button android:layout_weight=".30" android:layout_margin="2dp" 
       android:layout_height="60dp" android:layout_width="100dp" 
       android:textColor="#FFF" android:gravity="bottom|center" 
       android:textSize="12dp" android:id="@+id/ButtonAudio" android:background="@drawable/vid_red"/> 

      <Button android:layout_weight=".30" android:layout_height="60dp" android:layout_width="100dp" 
       android:gravity="bottom|center" android:background="@drawable/redblank" 
       android:textColor="#E6E7E2" android:id="@+id/ButtonBrowse" android:layout_marginTop="2dp"/> 
      <Button android:layout_weight=".30" android:layout_margin="2dp" 
       android:layout_height="60dp" android:layout_width="100dp" 
       android:textColor="#FFF" android:gravity="bottom|center" 
       android:textSize="12dp" android:background="@drawable/reddelete" android:id="@+id/ButtonDelete"/> 

     </LinearLayout> 
</RelativeLayout> 

Khi tôi thêm chân để listview bằng

View header = getLayoutInflater().inflate(R.layout.header, null); 
View footer = getLayoutInflater().inflate(R.layout.footer, null); 
ListView lv = getListView(); 

// setting header for the list view 
lv.addHeaderView(header); 
lv.addFooterView(footer); 
setListAdapter(new ArrayAdapter<String>(AudioListActivity.this, R.layout.row_audio, R.id.label, db_results)); 

Nó đi ngay bên dưới mục listview cuối cùng. Tôi muốn footer ở dưới đáy. Làm thế nào tôi có thể đạt được nó ??

PS: Tiêu đề hoàn toàn nằm ở trên cùng.

cảm ơn thời gian của bạn trước.

+0

đâu là bố trí cho listview? – PravinCG

+0

Tôi không có bố cục ListView riêng biệt. Tôi đã cung cấp mã listview ở trên và trong mã tôi đã truy xuất lại mã. là có một cách để bao gồm listview và fooer tiêu đề trong một bố trí và thực hiện ?? Làm ơn làm ơn đi. –

+0

Điều này [LInk] (http://blog.maxaller.name/2010/05/attaching-a-sticky-headerfooter-to-an-android-listview/) có ví dụ hoàn hảo chỉ cần có một cái nhìn .... cũng kiểm tra Câu hỏi này ... [giữa chúng tôi] (http://stackoverflow.com/questions/6121186/android-listview-with-header-and-footer-buttons) – Hanry

Trả lời

6

cho kịch bản của bạn tôi nghĩ rằng bạn cần một cái gì đó tương tự như sau.

<RelativeLayout> 
    <include android:id="@+id/header" layout="@layout/header" android:layout_width="fill_parent" android:layout_alignParentTop="true" /> 

    <include android:id="@+id/footer" layout="@layout/footer" android:layout_width="fill_parent" android:layout_alignParentBottom="true" /> 

    <ListView android:layout_below="@id/header" android:layout_above="@id/footer"/> 
</RelativeLayout> 
3

Nó hoạt động như dự định. Chế độ xem chân trang sẽ ở cuối danh sách. Trong trường hợp bạn muốn có một cái gì đó tĩnh ở dưới cùng của màn hình, bạn cần phải sử dụng RelativeLayout với chân của bạn như alignParentBottom và danh sách trên đầu trang của nó.

Ahh tôi tìm thấy một câu hỏi tương tự và câu trả lời cũng là như nhau :)

Android ListView Footer View not being placed on the bottom of the screen

+0

không giúp eitehr: ( –

+0

bạn đã làm gì và bạn đang làm gì bây giờ? – PravinCG

+0

Tôi đã thay đổi bố cục trên cùng của bàn làm bố cục listview, vẫn giữ nguyên, không có gì thay đổi.Tôi muốn chân trang được cố định ở phía dưới. –

0

Hãy thử điều này ..

<ListView 
     android:id="@+id/your_id" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     tools:listfooter="@layout/your_layout" />