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 ScrollViewto 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>
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: