2011-08-05 41 views
6

我有一個列表視圖如下安卓:頁腳在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> 

,我有頁腳如下

<?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> 

當我頁腳添加到使用

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)); 
列表視圖

它直接位於最後一個listview項目的下方。我希望頁腳處於底部。我怎麼能實現它?

PS:標題完美地位於頂部。

感謝您的時間提前。

+0

這裏是列表視圖的佈局? – PravinCG

+0

我沒有單獨的ListView佈局。我已經給出了上面的列表視圖代碼,並在代碼中取回了代碼。有沒有一種方法可以在一個佈局中包含listview和header fooer並實現?請澄清我。 –

+0

這[LInk](http://blog.maxaller.name/2010/05/attaching-a-sticky-headerfooter-to-an-android-listview/)有一個完美的例子只是看看....也結帳這個問題... [在我們之間](http://stackoverflow.com/questions/6121186/android-listview-with-header-and-footer-buttons) – Hanry

回答

6

您的方案,我認爲你需要與此類似。

<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

它按預期工作。頁腳視圖將位於列表的底部。如果你想在屏幕底部有一些靜態的東西,你需要使用RelativeLayout和你的頁腳作爲alignParentBottom並在它的頂部列出。

啊我發現了另一個類似的問題,答案也是一樣:)

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

+0

沒有幫助eitehr :( –

+0

你做了什麼你現在得到什麼? – PravinCG

+0

我改變了頁腳的頂部佈局作爲listview佈局,仍然是一樣的,沒有任何改變,我希望頁腳被固定在底部,似乎不能通過android實現 –

0

試試這個..

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