【问题标题】:RecyclerView inside fragment not scrolling in Android API 22片段内的 RecyclerView 在 Android API 22 中不滚动
【发布时间】: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


【解决方案1】:

原来问题出在我使用片段的另一个文件中,那里有一个 AppBarLayout,由于某种原因阻止了旧 API 中的滚动。 删除了 AppBarLayout,它工作正常。

编辑:我找到了一个更好的解决方案,不需要删除 AppBarLayout 我没有正常隐藏和取消隐藏片段,而是使用了 setVisibility(GONE/VISIVILE) 并且它也以某种方式起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-25
    • 2016-05-10
    • 1970-01-01
    • 2023-03-03
    • 2019-03-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多