Footer below list view fixed at the bottom of the screen
11,964
Solution 1
Better use RelativeLayout
Explain the implementation:
- add the footer view to be aligned at the bottom of the screen
android:layout_alignParentBottom="true"
- then add the listview above the footer layout
android:layout_above="@+id/LinearLayout1"
- make your listview to fill the screen
android:layout_width="fill_parent"
andandroid:layout_height="fill_parent"
Change at your code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/LinearLayout1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1"
android:divider="#BE6D79"
android:dividerHeight="3dp" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@color/darkDetna"
android:orientation="horizontal" >
<Button
android:id="@+id/contactBtn"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:background="@drawable/listselector"
android:paddingRight="0dip"
android:text="Contact" />
<Button
android:id="@+id/faq"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:background="@drawable/listselector"
android:padding="0dip"
android:text="Terms And Conditions" />
<Button
android:id="@+id/feedback"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:background="@drawable/listselector"
android:padding="0dip"
android:text="Feedback " />
<Button
android:id="@+id/fullSIte"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:background="@drawable/listselector"
android:padding="0dip"
android:text="Full Site" />
</LinearLayout>
</RelativeLayout>
Solution 2
If you dont want to use a RelativeLayout you can set android:layout_gravity="bottom"
on the 2nd linearlayout
Solution 3
You can use RelativeLayout instead of LinearLayout and then add the view to the bottom of the RelativeLayout using android:layout_alignParentBottom="true"
<?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="@color/white"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:divider="#BE6D79"
android:dividerHeight="3dp" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:background="@color/darkDetna"
android:orientation="horizontal"
android:layout_alignParentBottom="true" >
<Button
android:id="@+id/contactBtn"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:background="@drawable/listselector"
android:paddingRight="0dip"
android:text="Contact" />
<Button
android:id="@+id/faq"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:background="@drawable/listselector"
android:padding="0dip"
android:text="Terms And Conditions" />
<Button
android:id="@+id/feedback"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:background="@drawable/listselector"
android:padding="0dip"
android:text="Feedback " />
<Button
android:id="@+id/fullSIte"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_weight="1"
android:background="@drawable/listselector"
android:padding="0dip"
android:text="Full Site" />
</LinearLayout>
Author by
user1743673
Updated on June 15, 2022Comments
-
user1743673 almost 2 years
I was trying to have a footer below my listview.
This is how m doing.
<?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:background="@color/white" android:orientation="vertical" > <ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:divider="#BE6D79" android:dividerHeight="3dp" /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="30dp" android:background="@color/darkDetna" android:orientation="horizontal" > <Button android:id="@+id/contactBtn" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_weight="1" android:background="@drawable/listselector" android:paddingRight="0dip" android:text="Contact" /> <Button android:id="@+id/faq" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_weight="1" android:background="@drawable/listselector" android:padding="0dip" android:text="Terms And Conditions" /> <Button android:id="@+id/feedback" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_weight="1" android:background="@drawable/listselector" android:padding="0dip" android:text="Feedback " /> <Button android:id="@+id/fullSIte" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_weight="1" android:background="@drawable/listselector" android:padding="0dip" android:text="Full Site" /> </LinearLayout> </LinearLayout>
here
but the problem is the list content is small or there is only one list item the footer ll be below the list view.
I want the footer to be fixed to the bottom of the screen.
Thanks in advance for you time and help.