简体   繁体   中英

How to fix the bottomNavigationView to the bottom in Coordinator Layout?

In my project, I have added a Drawer Layout which as has a coordinatorLayout. The coordinatorLayout has a AppBarLayout, how can i place the BottomNavigationView to the bottom of Coordinator Layout?

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer_layout"
android:fitsSystemWindows="true">

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

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_height="192dp"
        android:layout_width="match_parent">

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
        android:fillViewport="true">

        <include
            android:id="@+id/layout" layout="@layout/activity_main_body"
            android:layout_height="match_parent"
            android:layout_width="match_parent"/>
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        <!-- I had anchor_gravity="bottom" but that didn't work-->
        android:background="@color/secondaryColor"
        app:itemIconTint="@color/secondaryDarkColor"
        app:itemTextColor="@color/primaryTextColor"
        app:menu="@menu/bottom_navigation_items"/>

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

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true" />


</android.support.v4.widget.DrawerLayout>

This is the code, how should i place the BottomNavigationView?

Just add android:layout_gravity="bottom" in android.support.design.widget.BottomNavigationView

and it should go to the bottom of the screen.

<android.support.design.widget.BottomNavigationView
            android:id="@+id/navigation"
            android:layout_width="match_parent"
            android:layout_gravity="bottom"
            android:layout_height="wrap_content"
            android:background="@color/secondaryColor"
            app:itemIconTint="@color/secondaryDarkColor"
            app:itemTextColor="@color/primaryTextColor"
            app:menu="@menu/bottom_navigation_items"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM