I have following layout in my application:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:background="@drawable/bbg">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TextView
android:id="@+id/Title"
android:text="@string/order_status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="26sp"
android:textColor="#000000"
android:shadowColor="#FFFFFF"
android:shadowDx="0.5"
android:shadowDy="0.5"
android:shadowRadius="1.0"/>
<LinearLayout
android:orientation="vertical"
android:id="@+id/MainStatusWindow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="10sp"
android:background="@drawable/rounded_corners">
<TextView
android:id="@+id/RateInfo"
android:text=""
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_margin="10sp"
android:textColor="#5C5C5C"/>
<ImageView
android:src="@drawable/line"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"/>
<TextView
android:id="@+id/OrderStatus"
android:text="@string/please_wait"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="20sp"
android:layout_margin="10sp"
android:textColor="#222222"/>
<ImageView
android:src="@drawable/line"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"/>
<TextView
android:id="@+id/TimerStatus"
android:text="0:00"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="50sp"
android:layout_margin="10sp"
android:textColor="#222222"/>
</LinearLayout>
<Button android:id="@+id/Cancel"
android:layout_marginTop="10sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel_order"
android:textSize="18sp"
android:textColor="#111111"
android:layout_alignParentBottom="true"
android:background="@drawable/button_red"/>
</LinearLayout>
</ScrollView>
I need to last button to be on the bottom of page. Picture bellow shows what I need (On the left what I have, on the right what I need).
Thank you.
You can set the layout_height="0dp" of your header, footer and ScrollView and define a layout_weight . Just play around with the values until you find out which works best. The resulting heights of header and footer would dynamically change with the screensize.
To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .
Use LinearLayout in your root Layout ( android:orientation="vertical" ) The main attribute is ndroid:gravity="bottom" , let the child View on the bottom of Layout.
The general layout organization should be:
<LinearLayout orientation="vertical">
<ScrollView android:layout_weight="1"
android:width="fill_parent"
android:height="wrap_content">
... linear layout with your TextViews ...
</ScrollView>
<Button/>
</LinearLayout>
The layout_weight="1"
attribute causes that view to fill the available space in the outer LinearLayout and will push your button to the bottom.
Edit - if you want the buttons to scroll as well, then you should follow Romain Guy's article, using fillViewPort
and setting a layout_weight
on one of your LinearLayout
children.
Have you tried android:fillViewPort= true in ScrollView ?
Check here,
http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/
You can use put your ScrollView and the button inside a RelativeLayout and set android:layout_alignParentBottom for the button.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With