Reputation: 1017
I have a button that's below a ScrollView
, the button is set to align to the parents bottom. The scroll view is set to wrap_content
for its height. Once the ScrollView
is filled with content it appears beneath the button. How can I set it to not go behind the button, for the ScrollView
to end when the button begins?
I've tried placing android:layout_below
in the bottom button, and when that didn't work I tried layout_above
in the ScrollView
for above the button. That last one caused my app to crash on start, no idea why. The first one once the ScrollView
is longer than the screen it causes the button to be placed underneath with no way to access it.
Here's my XML file.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_blue"
android:padding="5dp"
tools:context=".MainActivity" >
<EditText
android:id="@+id/editText_query"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/queryPromt"
android:imeOptions="actionNext"
android:inputType="text"
android:textColor="#000" />
<EditText
android:id="@+id/editText_tag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editText_query"
android:layout_marginTop="10dp"
android:layout_toLeftOf="@+id/saveButton"
android:hint="@string/tagPrompt"
android:imeOptions="actionDone"
android:inputType="text" />
<Button
android:id="@id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/editText_query"
android:text="@string/save" />
<TextView
android:id="@+id/textView_taggedSearches"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignRight="@id/saveButton"
android:layout_below="@id/saveButton"
android:layout_marginTop="10dp"
android:background="#666"
android:gravity="center_horizontal"
android:text="@string/taggedSearches"
android:textColor="#FFF"
android:textSize="18sp" />
<ScrollView
android:id="@+id/scrollView_query"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textView_taggedSearches"
android:padding="5dp" >
<TableLayout
android:id="@+id/tableLayout_query"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:stretchColumns="*" >
</TableLayout>
</ScrollView>
<Button
android:id="@+id/button_clearTags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/clearTags" />
</RelativeLayout>
Upvotes: 1
Views: 164
Reputation: 6311
You can use layout_weight for this. If you set layout_height to "0px" you can use layout_weight to distribute the remaining parent space between sibling items.
In this case you want the button to have its normal size, and the scrollview to occupy whatever space remains. This should give you the general idea:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Upvotes: 0
Reputation: 2865
I did this before in my project. and here is my xml code. you can modify it as per your usage.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="This text view should act as header " />
<ScrollView android:layout_marginBottom="50dip" android:id="@+id/ScrollView01" android:layout_height="wrap_content" android:layout_width="fill_parent">
<RadioGroup android:id="@+id/RadioGroup01" android:layout_width="wrap_content" android:layout_height="wrap_content">
<RadioButton android:id="@+id/RadioButton01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
<RadioButton android:id="@+id/RadioButton11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
</RadioGroup>
</ScrollView>
<RelativeLayout android:layout_marginTop="-50dip" android:gravity="bottom" android:layout_height="wrap_content" android:layout_width="fill_parent">
<TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1">
<TableRow>
<Button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="One"/>
<Button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Two" android:layout_gravity="center_vertical"/>
<Button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Three" android:layout_gravity="right"/>
</TableRow>
</TableLayout>
</RelativeLayout>
</LinearLayout>
Upvotes: 0
Reputation: 6978
Try adding
android:layout_below="@id/scrollView_query"
to the last button
Upvotes: 1