【问题标题】:Handle both NavigationView and page content处理 NavigationView 和页面内容
【发布时间】:2017-11-15 02:53:44
【问题描述】:

我的 NavigationView 显示在页面内容的后面。所以我尝试在我的 NavigationView 上使用 bringToFront:页面内容位于 NavigationView 后面,BUT 变得不可点击/不可滚动(页面内容是一个包含多个项目的 recyclerView)。

如何同时处理 NavigationView 和页面内容? 即使 NavigationView 关闭,RecyclerView 也是不可点击/不可滚动的

这是我的布局文件:

<?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>

【问题讨论】:

    标签: android android-recyclerview drawerlayout navigationview android-elevation


    【解决方案1】:

    受 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>
    

    【讨论】:

      【解决方案2】:

      如下更新您的布局:

      <?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>
      

      【讨论】:

      • 有了这个布局,我可以看到工具栏和导航视图,但是 RecyclerView 是不可见的。
      猜你喜欢
      • 2013-08-15
      • 2021-12-23
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-15
      相关资源
      最近更新 更多