我确信我错过了一些简单的方法来实现这一点,但是我已经完成了所有已知的组合,以便得到我正在寻找的工作.当ListView项目没有填满页面时,我正试图让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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
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);
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试过的事情包括:
乡亲!我需要做这样的布局:我有listview,我需要把按钮放在它的顶部和底部,即当用户滚动列表到最后,他可以看到底部按钮,当用户在顶部时列表,他可以看到顶部按钮.但是当用户处于listview的"中间"时,他看不到这些按钮.我不知道该怎么做.感谢帮助.
UPDATE
listView=(ListView)findViewById(R.id.listSearchResults);
LayoutInflater inflater=this.getLayoutInflater();
View header=inflater.inflate(R.layout.list_header, null);
btnBack=(Button)header.findViewById(R.id.btnBack);
btnBack.setOnClickListener(this);
btnBack.setEnabled(false);
listView.addHeaderView(header);
View footer=inflater.inflate(R.layout.list_footer, null);
btnForward=(Button)footer.findViewById(R.id.btnForward);
btnForward.setOnClickListener(this);
btnForward.setEnabled(false);
listView.addFooterView(footer);
Run Code Online (Sandbox Code Playgroud)