【发布时间】:2019-07-28 12:01:13
【问题描述】:
我在 Fragment 内的 ScrollView 中创建了一个 RecyclerView 来显示多个通知。在 Android API 28 上它工作得很好,但在 API 22 上它没有滚动,除非我关闭片段并再次打开它,然后它会在新位置显示 RecyclerView(好像我滚动了,当片段是显示)。
我试过了:
1- 将 ScrollView 更改为 NestedScrollView
2- 完全移除 ScrollView 并仅使用 RecyclerView
3- 移除 RecyclerView 元素的 onClickListeners
这是片段的代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/common_google_signin_btn_text_dark_default"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:padding="20dp"
android:id="@+id/my_recycler_view_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
编辑:我删除了滚动布局,但问题仍然存在。我也试过了,它在 android API 23 及更高版本上完美运行。滚动仅在 android API 22 及更早版本上停止工作。
我只是尝试让回收站视图自行保留,但它仍然没有滚动。
【问题讨论】:
-
滚动视图不需要直接在 ConstraintLayout 中使用 RecyclerView ,您可以将片段中的 RecyclerView 设置代码添加到您的问题中吗?
-
在滚动视图中,滚动视图布局中的所有东西都不需要再次使用线性布局
-
我需要滚动视图和线性视图;我删除了其他视图以缩短代码。滚动视图和回收器视图都没有滚动。
-
尝试将你的 RecyclerView 放在另一个视图中,例如 LinearLayout。另外,将高度和宽度设置为 match_parent。
标签: java android android-recyclerview