6

I have a listview as below

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:background="#E6E7E2">
    <ImageView android:id="@+id/Thumbnail" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:src="@drawable/icon" />
    <TextView android:id="@+id/FilePath" android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:textColor="#E6E7E2"
        />
</LinearLayout>

and I have the footer as below

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent" android:layout_gravity="bottom">
    <LinearLayout android:layout_width="fill_parent" 
            android:layout_alignParentBottom="true" 
            android:layout_height="wrap_content"
            android:id="@+id/layoutfooterbutton" android:layout_gravity="bottom">

            <Button android:layout_weight=".30" android:layout_margin="2dp"
                android:layout_height="60dp" android:layout_width="100dp"
                android:textColor="#FFF" android:gravity="bottom|center"
                android:textSize="12dp" android:id="@+id/ButtonAudio" android:background="@drawable/vid_red"/>

            <Button android:layout_weight=".30" android:layout_height="60dp" android:layout_width="100dp"
                android:gravity="bottom|center" android:background="@drawable/redblank"
                android:textColor="#E6E7E2" android:id="@+id/ButtonBrowse" android:layout_marginTop="2dp"/>
            <Button android:layout_weight=".30" android:layout_margin="2dp"
                android:layout_height="60dp" android:layout_width="100dp"
                android:textColor="#FFF" android:gravity="bottom|center"
                android:textSize="12dp" android:background="@drawable/reddelete" android:id="@+id/ButtonDelete"/>

        </LinearLayout>
</RelativeLayout>

When I add the footer to the listview using

View header = getLayoutInflater().inflate(R.layout.header, null);
View footer = getLayoutInflater().inflate(R.layout.footer, null);
ListView lv = getListView();

// setting header for the list view
lv.addHeaderView(header);
lv.addFooterView(footer);
setListAdapter(new ArrayAdapter<String>(AudioListActivity.this, R.layout.row_audio,  R.id.label, db_results));

It goes to right below the last listview item. I want the footer to be in the bottom. How can I acheive it??

PS: Header perfectly sits on the top.

thanks for your time in advance.

kannappan
  • 2,250
  • 3
  • 25
  • 35
Jay Mayu
  • 17,023
  • 32
  • 114
  • 148
  • where is the layout for listview? – PravinCG Aug 05 '11 at 04:29
  • I dont have a seperate ListView layout. I have given the listview code above and in the code I retreived the code. is there a way to include listview and header fooer in one layout and implement?? Please clarify me. – Jay Mayu Aug 05 '11 at 04:39
  • This [LInk](http://blog.maxaller.name/2010/05/attaching-a-sticky-headerfooter-to-an-android-listview/) has perfect example just take a look.... also checkout this Question...[amongst us](http://stackoverflow.com/questions/6121186/android-listview-with-header-and-footer-buttons) – Hanry Aug 05 '11 at 04:50

3 Answers3

6

for your scenario i think you need something similar to this.

<RelativeLayout>
    <include android:id="@+id/header" layout="@layout/header" android:layout_width="fill_parent" android:layout_alignParentTop="true" />

    <include android:id="@+id/footer" layout="@layout/footer" android:layout_width="fill_parent" android:layout_alignParentBottom="true" /> 

    <ListView android:layout_below="@id/header" android:layout_above="@id/footer"/> 
</RelativeLayout>
Samuel
  • 9,883
  • 5
  • 45
  • 57
3

It is working as intended. The footer view will be at the bottom of the list. In case you want to have something static at the bottom of the screen you need to use RelativeLayout with your footer as alignParentBottom and list over the top of it.

Ahh I found another similar question and the answer is also the same :)

Android ListView Footer View not being placed on the bottom of the screen

Community
  • 1
  • 1
PravinCG
  • 7,688
  • 3
  • 30
  • 55
  • what did you do and what are you getting now? – PravinCG Aug 05 '11 at 04:58
  • I changed the footer's top layout as the listview layout, still its same. nothing changed. I want the footer to be fixed in the bottom. Seems can't acheive this via android – Jay Mayu Aug 05 '11 at 05:22
0

Try this..

<ListView
        android:id="@+id/your_id"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:listfooter="@layout/your_layout" />
Akshatha S R
  • 1,237
  • 1
  • 15
  • 30