java - NavigationDrawer 内的 RecyclerView 不滚动
问题描述
我已经开始了一个项目,在这个项目中,我在 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>
推荐阅读
- python - 如何在 Python 中解密后关闭 MS Office 文件?
- python - RegEx :检查字符串是否在包含至少 3 个单词的引号之间有任何子字符串(以空格分隔)
- reactjs - 样式化组件 w/o defaultProps w/ typescript
- java - Apache Flink:如何在单元测试中更新源函数?
- regex - Logstash 解析方括号内的数据
- tabular - 制表符 - 强制 setRenderMode 为标准
- html - 将图像添加到导航栏并指定导航栏链接
- java - 将一个数组中的元素映射到另一个数组
- c# - 使用 TPL 数据流:如何确保同一类别的项目按到达顺序进行处理?
- javascript - 如何构造此异步函数以获取同步响应