How to get a TextView at the bottom of the screen under a listview?
I'm making a settings screen in my android app. This list of course has a
pre defined set of options (notifications/colors/log out/etc.). So I
decided to create the list statically in xml. Because the list should
equally well display if it has more content than the screen I nested my
LinearLayout within a ScrollView (couldn't use a ListView because I want
to statically define the items in it).
This works fine with the following code now:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/black" >
<TextView
android:layout_width="fill_parent"
android:layout_height="80dp"
android:paddingTop="30dp"
android:text="@string/account_notifications"
android:background="@color/white"
android:layout_marginBottom="1dp"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="80dp"
android:text="@string/colors"
android:background="@color/white"
android:layout_marginBottom="1dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="80dp"
android:text="@string/log_out"
android:background="@color/white"
android:layout_marginBottom="1dp" />
</LinearLayout>
</ScrollView>
As you can see I set the background of the LinearLayout to black and the
items to white, with a marginBottom of 1dp, so that there is a separator
between the list items. I now want the logout TextView always at the
bottom of the screen. In case there are more items than the screen can
hold, the Logout should simply be situated at the end of the list.
To get the logout to the bottom of the screen I found some solutions in
this SO question. I first use the first suggestion like so:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/black" >
<TextView
android:layout_width="fill_parent"
android:layout_height="@dimen/list_item_height"
android:text="@string/account_notifications"
android:background="@color/white"
android:layout_marginBottom="1dp"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="@dimen/list_item_height"
android:text="@string/colors"
android:background="@color/white"
android:layout_marginBottom="1dp" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="@dimen/list_item_height"
android:text="@string/log_out"
android:background="@color/white"
android:layout_marginBottom="1dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</ScrollView>
This surprisingly makes the logout TextView totally disappear. So I tried
the second suggestion like so:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/black" >
<TextView
android:layout_width="fill_parent"
android:layout_height="@dimen/list_item_height"
android:layout_weight="1"
android:text="@string/account_notifications"
android:background="@color/white"
android:layout_marginBottom="1dp"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="@dimen/list_item_height"
android:layout_weight="1"
android:text="@string/colors"
android:background="@color/white"
android:layout_marginBottom="1dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="@dimen/list_item_height"
android:text="@string/log_out"
android:background="@color/white"
android:layout_marginBottom="1dp" />
</LinearLayout>
</ScrollView>
But this unfortunately doesn't do anything either. No clue why not.
So my question, does anybody know how I can get my logout to the bottom of
the screen, or in case the list is to long for the screen, to the bottom
of the list.
All tips are welcome!
No comments:
Post a Comment