开发者

Setting footer to ListView

everyone. Can you help me with setting footer to ListView? I've described footer in layouts, and then:

View footer = getLayoutInflater().inflate(R.layout.bottom, getListView(), false);
getListView().addFooterView(footer);

But it didn't appear... Can you give an example? Also I need to set the height of footer dynamically. Here is the code of 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="fi开发者_JS百科ll_parent"
                  android:textColor="#000000"
                  android:textStyle="bold"
                  android:text="Loading..."/>
</LinearLayout>


There can be few reasons for this, Have you added your code

getListView().addFooterView(footer); before the setAdapter of ListView ? If yes.

There might be problem in xml layout, If your listview is wrap_content and your footerlayout has fill_parent , Footer might not appear unless some text is there in your textview of footer layout.

Change the listview layout_width="fill_parent" and footer layout's layout_width="fill_parent"

To quickly check , give a background color to your footer layout and see its placement. Hope it helps.


The best way to do this is with RelativeLayout.

1) Create a RelativeLayout for the whole layout. 2) Create two views, perhaps ListView and LinearLayout for the footer. 3) Make the listView aligned to the parent top with a bottom margin equal to the height of the footer view or linear layout. 4) make the linear layout aligned the parent bottom

Done. Hope this helps.

EDIT:

Some quick code to try and get the point across:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜