The ultimate solution to the Android NestedScrollView nested RecyclerView sliding freeze problem

If it is the following page layout: NestedScrollView nested RecyclerView
insert image description here
As the recyclerVIew loads, the more items there are, you will find that the sliding is stuck; there are two general solutions:

Solution 1: Cancel the sliding of recyclerVIew

	mRecyclerView.setNestedScrollingEnabled(false);

This solution may solve most problems. But if there is a loaded picture in the item. But it might not work.
You can try option two;

Solution 2: Use CoordinatorLayout + AppBarLayout to solve

That is, use AppBarLayout to wrap views that need to slide outside the list. In this way, the linkage can be realized; note that it must not be set at this time

mRecyclerView.setNestedScrollingEnabled(false);

The core code is as follows:

 <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:id="@+id/layout_data"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:overScrollMode="never"
            android:scrollbars="none">

            <com.google.android.material.appbar.AppBarLayout
                android:id="@+id/mAppBarLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@null"
                android:fadingEdge="none"
                app:elevation="0dp">

                <androidx.core.widget.NestedScrollView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:overScrollMode="never"
                    android:scrollbars="none"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed">

                    <ImageView
                        android:id="@+id/iv_top"
                        android:layout_width="match_parent"
                        android:layout_height="76dp"
                        android:scaleType="fitXY"
                        android:src="@mipmap/ic_estimate_title" />


                </androidx.core.widget.NestedScrollView>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="0dp"/>

            </com.google.android.material.appbar.AppBarLayout>

            <RelativeLayout
                android:id="@+id/relativeLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="-8dp"
                    android:layout_marginRight="-8dp"
                    android:background="@color/color_bg"
                    android:divider="@color/trans"
                    android:horizontalSpacing="0dp"
                    android:listSelector="@color/trans"
                    android:overScrollMode="never"
                    android:scrollbars="none"
                    android:verticalSpacing="12dp" />

            </RelativeLayout>


        </androidx.coordinatorlayout.widget.CoordinatorLayout>

You're done!

Guess you like

Origin blog.csdn.net/mingtiannihao0522/article/details/129322330