Android RelativeLayout : how to alignParentBottom when wrapped in a ScrollView?

android

Solution

Take the button out of the SCrollview, Wrap both the Scrollview and the Button in a Linear Layout, set the scrollview's height to 0dip and set it's weight to 1, do not set any weight property for the button, so the scrollview can occupy all the remaining space saving only the button's space way at the bottom.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ScrollView 
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

        ....lots of views...


        </LinearLayout>
    </ScrollView>

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:text="Button" />

</LinearLayout>

Problem

The problem I am having seems to be that if I have a view (e.g. myButton) inside a RelativeLayout set to alignParentBottom - (as per the code below) - and then wrap the RelativeLayout with a scrollview (necessary so the content will be viewable on smaller screens or when orientation changes to landscape) - then, when the parent bottom is NOT visible (for example when changed to landscape orientation) myButton is displayed at the TOP of the page - NOT the bottom. How can you align a view to the bottom of the screen and have it remain at the bottom even if the bottom is below the scroll? ``` <ScrollView android:id="@+id/mainScrollView" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:fillViewport="true"> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/topLayout" android:layout_width="fill_parent" android:layout_height="fill_parent"> ... lots of views and stuff <Button android:layout_alignParentBottom="true" android:id="@+id/myButton" android:text="Click Me" /> </RelativeLayout> </ScrollView> ```

Original source