Reputation: 3315
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>
Upvotes: 2
Views: 7566
Reputation: 413
Try this one:
Hope it helps:
<?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">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="420dp"
android:id="@+id/rel">
<ListView
android:id="@+id/list2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rel"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="fill_parent"
android:layout_height="50dip"
android:text="Bar of text that always stays at the bottom of the screen" />
</RelativeLayout>
</RelativeLayout>
Upvotes: 0
Reputation: 1974
Based on @CommonsWare answer:
<?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">
<ListView android:id="@+id/actionsListView"
android:layout_height="0px"
android:layout_width="fill_parent"
android:layout_weight="1"
android:transcriptMode="alwaysScroll"/>
<TextView android:text=""
android:id="@+id/progressTextLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"/>
</LinearLayout>
Upvotes: 0
Reputation: 1007399
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
.
Upvotes: 3
Reputation: 4414
Actually, it really sounds like you want to be using a footer, which ListView already has and does exactly what you describe.
Upvotes: 1
Reputation: 15130
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>
Upvotes: 1