处理NavigationView和页面内容

时间:2017-06-13 10:59:40

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

我的NavigationView显示在页面内容后面。所以我尝试在我的NavigationView上使用bringToFront:页面内容在NavigationView后面,但是变得无法点击/不可滚动(页面内容是带有多个项目的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>

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分: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>