Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Footer below list view fixed at the bottom of the screen

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.

like image 950
user1743673 Avatar asked Dec 21 '22 08:12

user1743673


1 Answers

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" and android: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>
like image 124
madlymad Avatar answered Jan 29 '23 06:01

madlymad