java - NavigationDrawer 内的 RecyclerView 不滚动

标签 java android xml

我已经启动了一个项目,在这个项目中我在 NavigationView 内部添加了一个 RecyclerView,但由于某种原因 RecylerView 不滚动。

https://cdn1.imggmi.com/uploads/2019/7/31/d58464f32d8ebb24885b876f81ce2274-full.png

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    tools:openDrawer="end">

    <com.google.android.material.navigation.NavigationView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="right">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <include layout="@layout/digikala_navigation_drawer_header" android:id="@+id/navigationDrawerHeader"/>
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/navigationDrawerRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/navigationDrawerHeader">

        </androidx.recyclerview.widget.RecyclerView>
        </RelativeLayout>
    </com.google.android.material.navigation.NavigationView>

...

最佳答案

您应该使用navigationView更改内容位置(navigationView必须是最后一个子级)

    <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="end"
        tools:openDrawer="end">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
           // Content
        </LinearLayout>

        <com.google.android.material.navigation.NavigationView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="right">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            <include layout="@layout/digikala_navigation_drawer_header" android:id="@+id/navigationDrawerHeader"/>
            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/navigationDrawerRecyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@id/navigationDrawerHeader">

            </androidx.recyclerview.widget.RecyclerView>
            </RelativeLayout>
        </com.google.android.material.navigation.NavigationView>

关于java - NavigationDrawer 内的 RecyclerView 不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57280707/

相关文章:

c# - 索引文件和在文件夹中查找文件的最快方法?

java - Hudson 上的 Maven 构建随机失败

android - Android 上的 Linux 内核 3.3 应用程序

java - 在 libgdx 对话框中绘制形状和图像

c++ - QDomDocument 无法打开文本中带有 & 的内容

java - Android - 我可以以编程方式覆盖 simple_list_item_1 颜色吗?

java - 如何将 Spring bean 从 EJB 项目发送到 Spring MVC 项目

java - 如何在 Java 中使用数组的一部分初始化列表

java - 连接嵌套文件夹上的文件内容

java - 在 ffmpeg for android studio 中的视频上叠加图像