大家。 你能帮我设置ListView的页脚吗?我在布局中描述了页脚,然后:
View footer = getLayoutInflater().inflate(R.layout.bottom, getListView(), false);
getListView().addFooterView(footer);
但它没有出现......你能举个例子吗?另外我需要动态设置页脚的高度。这是页脚代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#87ceeb"
>
<TextView android:id="@+id/loading"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#000000"
android:textStyle="bold"
android:text="Loading..."/>
</LinearLayout>
答案 0 :(得分:3)
这个原因很少, 你有没有添加你的代码
getListView()addFooterView(页脚)。在ListView的setAdapter之前?如是。
xml布局可能有问题, 如果你的listview是wrap_content而你的footerlayout有fill_parent,除非页脚布局的textview中有一些文字,否则页脚可能不会出现。
更改listview layout_width =“fill_parent”和页脚布局的layout_width =“fill_parent”
要快速检查,请为页脚布局提供背景颜色并查看其位置。 希望它有所帮助。
答案 1 :(得分:2)
执行此操作的最佳方法是使用RelativeLayout。
1)为整个布局创建RelativeLayout。 2)为页脚创建两个视图,可能是ListView和LinearLayout。 3)使listView与父顶部对齐,底边距等于页脚视图或线性布局的高度。 4)使线性布局与父底部对齐
完成。希望这会有所帮助。
编辑:
尝试解决问题的一些快速代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent" >
<ListView
android:id="@+id/list"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginBottom="50dp"
android:layout_alignParentTop="true" />
<TextView
android:text="Some text"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true" />
</RelativeLayout>