Search code examples
androidandroid-linearlayoutandroid-relativelayout

XML in Android Studio: Wrapcontent in RelativeLayout


I need to have items arranged vertically in this order: TextView, LinearLayout (under the textview), then BottomNavigationView. But the result is this:

enter image description here

I have this code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

    <TextView
            android:id="@+id/message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:textSize="30dp"
            android:gravity="center"
            android:layout_alignParentTop="true"
            android:text="Home"
            />

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:id="@+id/fragmentholder"
            android:orientation="vertical"></LinearLayout>

    <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:layout_alignParentBottom="true"
            android:background="?android:attr/windowBackground"

            app:menu="@menu/navigation"/>

</RelativeLayout>

What am I doing wrong?


Solution

  • Set this to the LinearLayout:

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/message"
        android:layout_above="@+id/navigation"
        android:id="@+id/fragmentholder"
        android:orientation="vertical">
     </LinearLayout>