简体   繁体   English

片段内的RecyclerView无法在Android API 22中滚动

[英]RecyclerView inside fragment not scrolling in Android API 22

I created a RecyclerView in a ScrollView inside a Fragment to display multiple notifications. 我在Fragment内的ScrollView中创建了RecyclerView,以显示多个通知。 On Android API 28 it's working perfectly, but on API 22 it's not scrolling, unless I close the fragment and open it again, then it shows the RecyclerView in the new position (as if I scrolled, it doesn't scroll while the fragment is shown). 在Android API 28上,它运行良好,但在API 22上,它没有滚动,除非我关闭片段并再次打开它,然后它在新位置显示RecyclerView(就像我滚动了一样,当片段处于显示)。

I tried: 我试过了:

1- Changing the ScrollView to NestedScrollView 1-将ScrollView更改为NestedScrollView

2- Removing the ScrollView completely and working with the RecyclerView only 2-完全删除ScrollView并仅使用RecyclerView

3- Removing the onClickListeners of the RecyclerView elements 3-删除RecyclerView元素的onClickListeners

Here is the code for the fragment 这是片段的代码

<?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"

        />

Edit: I removed the scroll layout, but the problem still persists. 编辑:我删除了滚动布局,但问题仍然存在。 I also tried it and it works perfectly on android API 23 and later. 我也尝试过,它可以在android API 23及更高版本上完美运行。 The scrolling only stops working on android API 22 and earlier. 滚动只会停止在android API 22及更早版本上的工作。

I just tried leaving the recycler view on its own, and it's still not scrolling. 我只是尝试独自保留回收器视图,但它仍然没有滚动。

Turns out the problem was in another file where I used the fragment, there was an AppBarLayout there which prevented the scrolling in older APIs for some reason. 原来问题出在我使用该片段的另一个文件中,那里有一个AppBarLayout,由于某种原因,它阻止了旧API的滚动。 Removed the AppBarLayout and it worked fine. 删除了AppBarLayout,它工作正常。

Edit: I found a better solution that didn't require removing AppBarLayout Instead of hiding and unhiding the fragment normally, I used setVisibility(GONE/VISIVILE) and it also somehow worked. 编辑:我找到了一个不需要删除AppBarLayout的更好的解决方案,而不是正常地隐藏和取消隐藏片段,我使用了setVisibility(GONE / VISIVILE),并且它也以某种方式起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM