如何正确地结合起来NavigationView和BottomNavigationView
问题描述:
我需要同时使用的元素,这是我的时刻:如何正确地结合起来NavigationView和BottomNavigationView
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<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"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorAccent"
app:menu="@menu/menu_bottom" />
</RelativeLayout>
我在这里的问题是,BottomNavigationView
在NavigationView
的前面,这不应该是这种情况(我正在谈论y指数)。我也尝试使用CoordinatorLayout
代替,但是BottomNavigationView
卡在显示屏的顶部。
答
我会简单地使用DrawerLayout
作为根元素,在DrawerLayout
的内部,您可以放置一个用于包含主屏幕的布局和用于菜单的NavigationView
。将BottomNavigationView放入主布局之后。
<android.support.v4.widget.DrawerLayout xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include layout="@layout/maincontent"/>
<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"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
maincontent.xml
<FrameLayout..>
...
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorAccent"
app:menu="@menu/menu_bottom" />
</FrameLayout>
的FrameLayout不支持'机器人:layout_alignParentBottom'。最好使用'RelativeLayout' – PYPL