Android Layout with ListView between a "top bar" and "bottom bar"
I accomplished what you're trying to do in a similar way, using IDs and the layout_below/layout_above attributes. The View
s are arranged in a different way, but the end result is the same. A ListView
between two other LinearLayout
s, one on top and one on bottom.
In the ListView
you can see I have:
android:layout_above="@+id/event_list_buttons"
android:layout_below="@id/title_container"
Those attributes position the ListView
between my top and bottom LinearLayout
s.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout style="@style/TitleBar">
<ImageView style="@style/TitleBarLogo" android:src="@drawable/logo_small_transparent" />
<View style="@style/TitleBarSpring" />
<ImageView style="@style/TitleBarSeparator" />
<ImageButton style="@style/TitleBarAction" android:src="@drawable/ic_title_refresh"
android:id="@+id/title_refresh_button" android:onClick="onClick" />
<ProgressBar style="@style/TitleBarProgressIndicator"
android:id="@+id/title_refresh_progress" android:visibility="gone" />
<ImageView style="@style/TitleBarSeparator" />
<ImageButton style="@style/TitleBarAction" android:src="@drawable/ic_title_search" />
</LinearLayout>
<ListView android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/android:list" android:layout_above="@+id/event_list_buttons"
android:layout_below="@id/title_container" android:fastScrollEnabled="true"
android:background="@color/white"></ListView>
<LinearLayout android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" android:id="@id/event_list_buttons"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:gravity="center_horizontal">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/events_list_view_organizing_button"
android:text="Organizing" android:onClick="onClick"></Button>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/events_list_view_attending_button"
android:text="Attending" android:onClick="onClick"></Button>
</LinearLayout>
</RelativeLayout>
Here comes a simple suggestion. Make a new XML and have a go with this.
<?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="vertical">
<TextView
android:text="Header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<TextView
android:text="Footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
</LinearLayout>
The problem with OPs layout is that the first linear layout is set as android:layout_height="fill_parent"
which will cause the first linear layout to fill the parent. It doesn't know that you're going to add further views. What you have to do is add views in the order that they know their size. So you know the size of the top par and the bottom bar, you can add those as android:layout_height="wrap_content"
. Then add the listview since it's size is unknown at compile time.