RecyclerView 滚动在 NestedScrollView 中缓慢地获得 frezz/scroll

问题描述

我有 nestedScrollView。在 nestedScrollView 中包含两个垂直滚动的 RecyclerView。

当第一个 RecyclerView 列表滚动结束/停止然后第二个 RecyclerView 列表开始滚动时。

当第一次开始滚动时,屏幕冻结/滚动缓慢。一段时间后平滑滚动发生。

为什么第一次滚动屏幕会冻结?如何避免屏幕冻结/缓慢滚动?

因为nestedScrollView,没有连续滚动的onScrollMethod和EndlessRecyclerViewScrollListener(用于分页)被调用。如何避免调用EndlessRecyclerViewScrollListener方法

我正在添加我的布局代码。等待答复。

                <androidx.swiperefreshlayout.widget.SwipeRefreshLayout              
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                        <androidx.core.widget.nestedScrollView
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="vertical">

                                <TextView
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_gravity="center"
                                    android:layout_margin="5dp"
                                    android:gravity="center"
                                    android:text="First List" />

                                <androidx.recyclerview.widget.RecyclerView
                                    android:id="@+id/rvFirstList"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:orientation="vertical"
                                    android:paddingTop="@dimen/dimen_4" />

                                <TextView
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_gravity="center"
                                    android:layout_margin="5dp"
                                    android:gravity="center"
                                    android:text="Secound List" />

                                <androidx.recyclerview.widget.RecyclerView
                                    android:id="@+id/secoundRecyclerView"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:orientation="vertical"
                                    android:paddingTop="@dimen/dimen_4" />

                            </LinearLayout> 

                        </androidx.core.widget.nestedScrollView>

                    
                </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>


解决方法

首先,您的视图层次结构似乎不正确。 您的开始标签是:

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
 <androidx.core.widget.NestedScrollView
  <LinearLayout

你的结束标签不匹配

  </androidx.core.widget.NestedScrollView>
 </LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

最后用 LinearLayout 交换 NestedScrollView。

然后尝试添加:

app:layout_behavior="@string/appbar_scrolling_view_behavior"

到你的

,

试试

recyclerView.setNestedScrollingEnabled(false)

在您的两个 recyclerViews 上