Search code examples
android-layoutlayoutalignmentandroid-linearlayoutandroid-relativelayout

Align LinearLayout over LinearLayout inside a RelativeLayout


I'm having a struggle understanding how to align layers one over another in the xml file. I searched for a solution but couldn't find one for my needs.

I have two LinearLayout inside a RelativeLayout. The first LinearLayout contains a RecycleView/ScrollView and the second LinearLayout contains some buttons.

I want to set the second LinearLayout over the first LinearLayout, but at the bottom of the RelativeLayout. See image below.

enter image description here

Here is what I tested (it will extend the first layout and hide the second).

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:id="@+id/first"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

<LinearLayout
    android:id="@+id/second"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_below="@+id/first"
    android:layout_alignParentBottom="true"
    app:layout_gravity="bottom">
</LinearLayout>

</RelativeLayout>

Do you have any idea how to achieve this?

PS. I don't want to use a BottomNavigationView instead of the second LinearLayout.


Solution

  • I managed to find a solution for my issue. I changed the first LinearLayout with a FrameLayout and everything works as it should. Please keep in mind that the second LinearLayout must stay under the FrameLayout. Cheers!