androidviewcoordinator-layout

Arrange views in Coordinator Layout


I have problem making my Frame layout be below Bottom Navigation Drawer (yes I put it on the top :)). Right now the top of Frame layout is hidden by BND because it is aligned with parents top just like BND instead of being aligned with BNDs bottom.

Here is the code:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    android:id="@+id/coordID">

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/BND_ID"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/m_navigation"
        />

    <FrameLayout
        android:id="@+id/fID2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </FrameLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/dummyFAB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="16dp"
        app:srcCompat="@drawable/ic_settings"
        app:layout_insetEdge="bottom" />

  </android.support.design.widget.CoordinatorLayout>

Solution

  • You should try to wrap them in RelativeLayout something like this:

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout 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"
        android:id="@+id/coordID">
    
        <RelativeLayout
            android:id="@+id/relativeLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
    
            <android.support.design.widget.BottomNavigationView
                android:id="@+id/BND_ID"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="?android:attr/windowBackground"
                app:menu="@menu/m_navigation" />
    
            <FrameLayout
                android:id="@+id/fID2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/BND_ID"/>
    
        </RelativeLayout>
    
        <android.support.design.widget.FloatingActionButton
            android:id="@+id/dummyFAB"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_gravity="end|bottom"
            app:layout_anchor="@+id/relativeLayout"
            app:layout_anchorGravity="right|bottom"
            app:layout_insetEdge="bottom"
            app:srcCompat="@drawable/ic_settings" />
    
    
    
    </android.support.design.widget.CoordinatorLayout>