我敢肯定,我錯過了一些簡單的事情來實現它,但已經通過每一個已知的組合,我可以拿出來得到我是什麼希望能夠工作。當ListView項不填充頁面時,我試圖讓ListView頁腳位於屏幕的底部。Android的ListView頁腳視圖不被放置在屏幕的底部
例如,我有一個帶有三個項目的ListView和一個FooterView(使用ListView的addFooterView)的頁面,我希望該footerView坐在屏幕的底部。當ListView包含足夠的項目以滾動屏幕時,footerView應位於列表的末尾(而不是屏幕的底部)。
下面列出了我嘗試使用的XML。任何和所有的幫助非常感謝!
Layout.xml
<?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"
android:background="@+drawable/background">
<ListView
android:id="@+id/menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="@android:color/transparent"
android:divider="@null">
</ListView></RelativeLayout>
ListViewRow.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
style="@style/Nationwide.menu">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nav_item"
style="@style/Nationwide.menu.row">
<ImageView
android:id="@+id/image_icon"
style="@style/Nationwide.menu.leftIcon" />
<TextView
android:id="@+id/nav_text"
style="@style/Nationwide.menu.text" />
<ImageView
android:id="@+id/chevron_symbol"
style="@style/Nationwide.menu.rightIcon" />
</LinearLayout>
<View
android:layout_height="1dp"
android:background="@drawable/nav_item_divider_dark" />
<View
android:layout_height="1dp"
android:background="@drawable/nav_item_divider_light" /></LinearLayout>
ListViewFooter.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true">
<View
android:id="@+id/footer_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true" /></RelativeLayout>
的Java
LayoutInflater inflater = this.getLayoutInflater();
View footerView = inflater.inflate(R.layout.footer, null);
footerView.findViewById(R.id.footer_image).setBackgroundDrawable(resources.getDrawable(R.drawable.cone_footer));
mMenuListView.addFooterView(footerView);
件
到目前爲止我嘗試的事情包括:
- 添加頁腳視圖作爲以上所示
- 添加繪製資源爲對一個的ListView背景(這導致ListView中不跨越整個寬度在奇數的方式在屏幕和滾動的由於9貼片可拉伸區域)
- 添加cone_footer作爲單獨的視圖中的佈局
提前感謝!
我很抱歉,但我沒有添加足夠的Java代碼。在將footerView添加到listView後,將運行此代碼。 mMenuListView.setAdapter(panel); – 2010-06-22 14:12:30