【问题标题】:RecyclerView scroll get frezz/scroll slowly in NestedScrollViewRecyclerView 滚动在 NestedScrollView 中变得缓慢/滚动
【发布时间】:2021-04-11 02:39:41
【问题描述】:

我有 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>


【问题讨论】:

    标签: android list android-recyclerview pagination android-nestedscrollview


    【解决方案1】:

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

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

    你的结束标签不匹配

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

    最后将 NestedScrollView 与 LinearLayout 交换。

    然后尝试添加这个:

    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    

    到你的 阻止

    【讨论】:

    • 我尝试在
    • 其实你做错了。通过使用一个recyclerview,您可以实现这一点。只需要在适配器中做一些额外的工作
    • 我想分别在 RecyclerView 上分页,
    【解决方案2】:

    试试

    recyclerView.setNestedScrollingEnabled(false)
    

    在你的两个 recyclerViews 上

    【讨论】:

    • 我已经写了这些,但问题没有解决
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    • 1970-01-01
    相关资源
    最近更新 更多