rockstar
rockstar

Reputation: 1328

How to add footer like view to a listview in android?

I have a list view, editText and button. editText and button are my footer to the listview. What is want is the footer to be positioned at the bottom of the screen and the listview to be scrollable above the footer. My layout is something like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ListView
    android:id="@android:id/list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:>

</ListView>


<EditText
    android:id="@+id/txtType"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_toLeftOf="@+id/add" />

<Button
    android:id="@+id/add"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:onClick="onClick"
    android:text="Add" />
 </RelativeLayout>

enter image description here

I have achieved above picture but my problem is that the listview scrolls below my footer. Footer is like floating over the listview. I want the listview to be scrollable above this footer only. help me

Upvotes: 2

Views: 2487

Answers (5)

Ravi1187342
Ravi1187342

Reputation: 1277

check out this this is working for me

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:background="@drawable/login_page_bg"
 android:layout_height="fill_parent"
 >

 <ListView  
     android:id="@android:id/list"
     android:layout_above="@+id/footerlayout"


     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     />



   <RelativeLayout 
    android:id="@+id/footerlayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    >

      <Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:onClick="onClickAddChild"
          android:text="Add+"/>
  </RelativeLayout>

 </RelativeLayout>

Upvotes: 0

Deva
Deva

Reputation: 3949

Just add this android:layout_above="@+id/txtType" to your ListView.

<?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:orientation="vertical" >
    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/txtType"
        android:layout_alignParentTop="true"
        android:="" >
    </ListView>
    <EditText
        android:id="@+id/txtType"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@+id/add" />
    <Button
        android:id="@+id/add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:onClick="onClick"
        android:text="Add" />
</RelativeLayout>

Upvotes: 0

Sandip Jadhav
Sandip Jadhav

Reputation: 7155

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

    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_above="@+id/bbar">

    </ListView>

    <RelativeLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:id="@+id/bbar">

        <EditText
            android:id="@+id/txtType"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@+id/add" />

        <Button
            android:id="@+id/add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:onClick="onClick"
            android:text="Add" />
    </RelativeLayout>
</RelativeLayout>

Upvotes: 7

Relsell
Relsell

Reputation: 771

Wrap Editbox and button in another LinearLayout, . then use alignParentBottom=true property for the Linear Layout .

Upvotes: 0

user4232
user4232

Reputation: 592

Give Editbox and button in another LinearLayout,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ListView
    android:id="@android:id/list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:>

</ListView>
 <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:gravity="center" >


<EditText
    android:id="@+id/txtType"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_toLeftOf="@+id/add" />

<Button
    android:id="@+id/add"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:onClick="onClick"
    android:text="Add" />
</LinearLayout>
 </RelativeLayout>

Thanks....

Upvotes: 0

Related Questions