views:

1944

answers:

3

Hi,

I'm having trouble setting up an Android Layout.

What I would like is a scrollable ListView followed by a small bar of text (TextView) that doesn't scroll and always stays at the bottom of the screen.

it would look like this:

ListViewItem1

ListViewItem2

ListViewItem3

Bar of Text Here (always displayed irrespective of scroll state of the ListView)

I've tried a bunch of different variations on this, but none shows the static text

Any thoughts as to where I'm going wrong?

TKS!

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout android:orientation="vertical"
     android:layout_width="fill_parent" android:layout_height="wrap_content">
     <ListView android:id="@+id/list2" android:layout_width="fill_parent"
      android:layout_height="fill_parent" />
    </LinearLayout>
    <TextView android:layout_width="fill_parent"
     android:layout_height="50dip" android:text="Bar of text that always stays at the bottom of the screen" />
</LinearLayout>
+2  A: 

Use a RelativeLayout. Anchor the TextView to the bottom using android:layout_alignParentBottom="true". Have the ListView fill the remainder.

Or, use a single LinearLayout, setting the ListView's android:layout_height to 0px and android:layout_weight to 1, and the TextView following the ListView as children of the LinearLayout.

CommonsWare
Did you mean "android:layout_width to 1" or "android:layout_weight to 1"?
Nemi
@Nemi: thanks for pointing that out -- I've fixed my original answer.
CommonsWare
+1  A: 

Use android:layout_weight to make your listview fill the remainder of the page not used by the static text.

like so:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="wrap_content">
        <ListView android:id="@+id/list2" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:layout_weight="1"/><!-- here's the important part-->
    </LinearLayout>
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="Bar of text that always stays at the bottom of the screen" />
</LinearLayout>
CodeFusionMobile
+1  A: 

Actually, it really sounds like you want to be using a footer, which ListView already has and does exactly what you describe.

Aurora
Actually, addFooterView seems to ensure that you can have the added view as the last element of the list, it wouldn't help in weighting it to the bottom of the screen.
f0ster