I am trying to make a button anchored to the bottom of the view and also bottom of the list if the list gets bigger than the view.
So I want them to look like this when list is smaller than screen:
and like this when bigger:
I know I should use RelativeLayout
to place the button at the bottom of the page with android:layout_alignParentBottom="true"
but when I also add android:layout_below="@id/table_wrapper"
my button's height will get messed up if content is smaller than view:
Is there anyone who know how I can accomplish this?
The simplified version of my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/book_layout_whole"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/table_wrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/vertical_header_table"
android:layout_width="85dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Day"
android:gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Day"
android:gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Day"
android:gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Day"
android:gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Day"
android:gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Day"
android:gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:text="Day"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#444444"></View>
<View
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#444444"></View>
<View
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#444444"></View>
<View
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#444444"></View>
<View
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#444444"></View>
<View
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#444444"></View>
<View
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#444444"></View>
</LinearLayout>
</LinearLayout>
<Button
android:text="load more"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/table_wrapper"
android:layout_alignParentBottom="true"
android:gravity="center"
android:padding="20dp"
/>
</RelativeLayout>
</ScrollView>
</LinearLayout>
Note 1:
removing android:layout_below="@id/table_wrapper"
will result in the button always being at the bottom of the screen, even when there list is bigger than the screen.
Note 2
Adding layout_weight
would not work, because the size of my view is dynamic.