The layout I try to implement is (I think) pretty simple.
One TextView expands depending on what is inside. Just below are two buttons (OK/Cancel).
I can make the buttons stick to the bottom of the screen and that works fine. But I would like to have those buttons just below the TextView. I have tried a lot of different things, but here is my latest layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ScrollView android:id="@+id/Scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<TextView
android:id="@+id/Text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</ScrollView>
<RelativeLayout android:id="@+id/buttons"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_below="@+id/Scroll"
android:layout_above="@+id/bottom"
>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button android:id="@+id/ButtonOK"
android:layout_height="80dp"
android:layout_width="fill_parent"
android:text="OK"
android:layout_weight="1"/>
<Button android:id="@+id/ButtonCancel"
android:layout_height="80dp"
android:layout_width="fill_parent"
android:text="Cancel"
android:layout_weight="1"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout android:id="@+id/bottom"
android:layout_height="0px"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
The empty linearlayout at the end is an (unsuccessful) attempt to prevent the view to extend past the bottom of the screen...
In everything I tried, either the buttons are at the bottom of the screen or they would go past it when the TextView is too big.
Here is a sketch of what I am trying to do :
Is the goal just to have a scrollable area that takes up the entire page minus the amount taken up by some buttons at the bottom?
If that's the case, you can use a LinearLayout
at the outer level and make use of weights:
<LinearLayout
android:layout_height="wrap_content"
orientation="vertical"...>
<ScrollView
android:layout_height="0dp"
android:layout_weight="1"
.../>
<LayoutWithButtons
android:layout_height="wrap_content"
..../>
</LinearLayout>
This should be the answer in xml
android:fillViewport="true"
http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/
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