0

我的NavigationView顯示在頁面內容的後面。因此,我試圖在我的NavigationView上使用bringToFront:頁面內容位於NavigationView的後面,但變得不可點擊/不可滾動(頁面內容是帶有多個項目的recyclerView)。處理NavigationView和頁面內容

我該如何處理NavigationView和頁面內容? 即使NavigationView關閉時,RecyclerView是不可點擊/ unscrollable

這是我的佈局文件:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:background="@color/background_color"> 


    <include android:id="@+id/mytoolbar" 
     layout="@layout/toolbar"/> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:layout_below="@+id/mytoolbar" 
     > 

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

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

    <RelativeLayout 
     android:id="@+id/layoutPlanVente" 
     android:layout_below="@+id/mytoolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recyclerViewProduitsVente" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scrollbars="vertical" 
      android:scrollbarSize="50dp" 
      android:orientation="vertical"> 

     </android.support.v7.widget.RecyclerView> 

    </RelativeLayout> 

</RelativeLayout> 

回答

0

更新您的佈局如下:

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

    <!-- Content --> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <include android:id="@+id/mytoolbar" 
      layout="@layout/toolbar"/> 

     <RelativeLayout 
      android:id="@+id/layoutPlanVente" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/recyclerViewProduitsVente" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scrollbars="vertical" 
       android:scrollbarSize="50dp" /> 
     </RelativeLayout> 
    </LinearLayout> 

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

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

使用此佈局,我可以看到工具欄和導航視圖,但RecyclerView不可見。 – macTAR

0

通過FAT答案的啓發我使它適用於這種佈局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:background="@color/background_color"> 

    <include android:id="@+id/mytoolbar" 
     layout="@layout/toolbar"/> 

    <android.support.v4.widget.DrawerLayout 
     android:id="@+id/drawer_layout" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:layout_below="@+id/mytoolbar" 
     > 

     <RelativeLayout 
      android:id="@+id/layoutPlanVente" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 


      <android.support.v7.widget.RecyclerView 
       android:id="@+id/recyclerViewProduitsVente" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scrollbars="vertical" 
       android:scrollbarThumbVertical="@drawable/scrollbar_custom" 
       android:orientation="vertical"> 
      </android.support.v7.widget.RecyclerView> 

     </RelativeLayout> 


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

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

</RelativeLayout>