2017-05-05 95 views
0

我需要同時使用的元素,這是我的時刻:如何正確地結合起來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> 

我在這裏的問題是,BottomNavigationViewNavigationView的前面,這不應該是這種情況(我正在談論y指數)。我也嘗試使用CoordinatorLayout代替,但是BottomNavigationView卡在顯示屏的頂部。

回答

0

我會簡單地使用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>  
+0

的FrameLayout不支持'機器人:layout_alignParentBottom'。最好使用'RelativeLayout' – PYPL

相關問題