user1743673
user1743673

Reputation: 99

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.

Upvotes: 4

Views: 12138

Answers (4)

madlymad
madlymad

Reputation: 6530

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>

Upvotes: 9

Tim
Tim

Reputation: 43314

If you dont want to use a RelativeLayout you can set android:layout_gravity="bottom" on the 2nd linearlayout

Upvotes: 1

Niko Adrianus Yuwono
Niko Adrianus Yuwono

Reputation: 11112

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>

Upvotes: 1

hasanghaforian
hasanghaforian

Reputation: 14022

You can use RelativeLayout as root view of your Layout.

Upvotes: 0

Related Questions