Search code examples
androidandroid-layoutalignmentscrollviewandroid-relativelayout

RelativeLayout inside ScrollView with a button aligned to bottom of its parent


I have a RelativeLayout structured in a "header/body/footer" style.

  • In the header section I have a TextView showing the title of the current fragment;

  • the body includes a ScrollView element wrapping a RelativeLayout which contains other elements;

  • finally, the footer just has a Button.

Specifically, the structure is the following:

<RelativeLayout>
    <TextView />                <!-- the header -->

    <ScrollView>                <!-- the body -->
        <RelativeLayout>
            <!-- other elements -->
        </RelativeLayout>
    </ScollView>

    <Button />                  <!-- the footer -->

</RelativeLayout>

Now, I want the button to be always to the bottom of the main RelativeLayout, so I assigned the property android:layout_alignParentBottom="true".

Also, the ScrollView must fill all the body, so the property android:fillViewport="true" has been set.

Problem: the fact is that the button in the footer goes over the final part of the ScrollView, thus hiding the final elements of the RelativeLayout containing the body. Is there any solution to overcome this issue?


Solution

  • try setting

    android:layout_above="@+id/id_of_your_button"
    

    on the ScrollView