Search code examples
androidandroid-layoutandroid-coordinatorlayoutbottomnavigationview

Placing BottomNavigationView below a Layout in CoordinatorLayout


<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinatorContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <!-- This coordinator Layout matches the parent's height, I want to height to match till the BottomNaviagtionView and not below it -->

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

    <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="@color/primaryDarkColor"
        app:itemIconTint="@color/primaryColor"
        android:layout_gravity="bottom"
        app:layout_scrollFlags="scroll|enterAlways|snap"
        app:itemTextColor="@color/primaryTextColor"
        app:menu="@menu/bottom_navigation_items"/>

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

In this Layout, I have placed a BottomNavigationView in a CoordinatorLayout and there is another CoordinatorLayout inside it. The Problem is that the BottomNavigationView overlaps the bottom part of the Inner Coordinator Layout. So need suggestions to make the Inner Coordinator Layout match_parent until BottomNavigationView and not below that.


Solution

  • Try this

    <LinearLayout
        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:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="match_parent">
    
        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/coordinatorContent"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="match_parent">
    
            <!-- This coordinator Layout matches the parent's height, I want to height to match till the BottomNaviagtionView and not below it -->
    
        </android.support.design.widget.CoordinatorLayout>
    
        <android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/primaryDarkColor"
            app:itemIconTint="@color/primaryColor"
            android:layout_gravity="bottom"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:itemTextColor="@color/primaryTextColor"
            app:menu="@menu/bottom_navigation_items"/>
    
    </LinearLayout>
    

    EDIT

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <android.support.design.widget.CoordinatorLayout
                android:id="@+id/coordinatorContent"
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:layout_height="match_parent">
    
    
            </android.support.design.widget.CoordinatorLayout>
    
            <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="#ff00"
                app:itemIconTint="#2639c9"
                android:layout_gravity="bottom"
                app:layout_scrollFlags="scroll|enterAlways|snap"
                app:itemTextColor="#0eec3b"
                app:menu="@menu/mymenu" />
        </LinearLayout>
    
    </android.support.design.widget.CoordinatorLayout>