ScrollView嵌套Recyclerview的滑动不流畅问题

ScrollView嵌套Recyclerview的滑动不流畅问题

场景分析

  • 每次滑动rv的时候,总是一卡一卡的是什么情况?
    分析添加的ScrollView可以得出聚焦问题,我们尝试一下;
    your_rv.setFocusable(false); your_rv.setFocusableInTouchMode(false);
    没起到一点作用…不要灰心我们分析问题

分析到了问题

当Recyclerview(Rv)与ScrollView(Sv)同时出现的时候,也就是把Rv嵌套进Sv里面的时候出现滑动焦点问题;

解决方案

1.把ScrollView修改为NestedScrollView

 * NestedScrollView is just like {@link android.widget.ScrollView}, but it supports acting
 * as both a nested scrolling parent and child on both new and old versions of Android.
 * Nested scrolling is enabled by default.
 */

—但对我而言没起到作用

2.在RecyclerView加入属性:

  • 静态代码:
     <com.jcodecraeer.xrecyclerview.XRecyclerView
                android:id="@+id/edg_search_rv"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:focusable="false"
                android:focusableInTouchMode="false" />
  • 动态代码:
        EDGMatterSearch_rv.setFocusable(false);
        EDGMatterSearch_rv.setFocusableInTouchMode(false);

以上静态动态任选其一
之后 我们需要给ItemView里面的任意控件设置焦点,来修复此问题;
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-H98QlBdK-1587021989916)(media/15864969980597/15864984153039.jpg)]
没能解决我的问题

3.把RecyclerView和ScrollView分离开来,不进行嵌套,使用显示隐藏来处理,如:

 <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="16dp"
        android:layout_marginRight="10dp"
        android:fadingEdge="none"
        android:focusable="false"
        android:overScrollMode="never"
        android:scrollbars="none"
        android:visibility="gone">

        <com.htmitech.MyView.EmptyLayout
            android:id="@+id/empty_matter_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/huise">
        </com.htmitech.MyView.EmptyLayout>

    </ScrollView>

    <com.jcodecraeer.xrecyclerview.XRecyclerView
        android:id="@+id/edg_search_rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
发布了81 篇原创文章 · 获赞 34 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_41914317/article/details/105559006