Search code examples
androidandroid-layoutandroid-scrollview

Button needs to be on the bottom


Without Scrollview, Button is on the bottom on the screen, which is the desired result. But as soon as I add the Scrollview, the button is not at the bottom of the screen anymore.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/create_account_view">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:id="@+id/scrollview_wrapper"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginTop="0dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginBottom="10dp"
                android:lines="1"
                android:gravity="center"
                android:textSize="16sp"/>

        </RelativeLayout>
    </ScrollView>
</RelativeLayout>  

Solution

  • Add another attribute to ScrollView:

    android:fillViewport="true"
    

    This way ScrollView height will respect child's android:layout_height="match_parent" attribute