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里面的任意控件设置焦点,来修复此问题;
在这里插入图片描述
没能解决我的问题

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" />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值