I created a RecyclerView in a ScrollView inside a Fragment to display multiple notifications. 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).
I tried:
1- Changing the ScrollView to NestedScrollView
2- Removing the ScrollView completely and working with the RecyclerView only
3- Removing the onClickListeners of the RecyclerView elements
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. The scrolling only stops working on android API 22 and earlier.
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. Removed the AppBarLayout and it worked fine.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.