我确信我错过了一些简单的东西来实现它,但是已经通过了我能想出的所有已知组合来得到我想要做的工作。当 ListView 项目未填满页面时,我试图让 ListView 页脚位于屏幕底部。
例如,我有一个包含三个项目的 ListView 和一个 FooterView(使用 ListView 的 addFooterView)的页面,我希望该 footerView 位于屏幕底部。当 ListView 包含足够的项目来滚动屏幕时,footerView 应该位于列表的末尾(而不是位于屏幕的底部)。
下面列出了我尝试使用的 XML。非常感谢任何和所有帮助!
布局.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>
爪哇
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 上添加可绘制资源作为背景(由于 9-Patch 可拉伸区域,这导致 ListView 无法跨越屏幕的整个宽度并以奇怪的方式滚动)
- 将 cone_footer 添加为布局中的单独视图
提前致谢!