Android NestedScrollView嵌套RecyclerView滑动卡顿问题简洁解决方案

Android NestedScrollView嵌套RecyclerView滑动卡顿问题简洁解决方案

其实仅仅需要给RecyclerView加一行控制代码即可:
mRecyclerView.setNestedScrollingEnabled(false);
这是最简洁的解决方案

过去网上也给出了其他的解决方法,比如是这样:
mLinearLayoutManager.setSmoothScrollbarEnabled(true);
mRecyclerView.setNestedScrollingEnabled(false);
但是实际上如果开发者再次给RecyclerView的布局控制器mLinearLayoutManager设置setSmoothScrollbarEnabled为true是多余的,因为在LinearLayoutManager的内部源代码中,默认的setSmoothScrollbarEnabled就是true,看LinearLayoutManager内部实现的源代码关键片段:
    /**
     * Works the same way as {@link android.widget.AbsListView#setSmoothScrollbarEnabled(boolean)}.
     * see {@link android.widget.AbsListView#setSmoothScrollbarEnabled(boolean)}
     */
    private boolean mSmoothScrollbarEnabled = true;
   /**
     * When smooth scrollbar is enabled, the position and size of the scrollbar thumb is computed
     * based on the number of visible pixels in the visible items. This however assumes that all
     * list items have similar or equal widths or heights (depending on list orientation).
     * If you use a list in which items have different dimensions, the scrollbar will change
     * appearance as the user scrolls through the list. To avoid this issue,  you need to disable
     * this property.
     *
     * When smooth scrollbar is disabled, the position and size of the scrollbar thumb is based
     * solely on the number of items in the adapter and the position of the visible items inside
     * the adapter. This provides a stable scrollbar as the user navigates through a list of items
     * with varying widths / heights.
     *
     * @param enabled Whether or not to enable smooth scrollbar.
     *
     * @see #setSmoothScrollbarEnabled(boolean)
     */
    public void setSmoothScrollbarEnabled(boolean enabled) {
        mSmoothScrollbarEnabled = enabled;
    }
即便不通过setSmoothScrollbarEnabled设置,mSmoothScrollbarEnabled已经为true了。因此在上层中再次setSmoothScrollbarEnabled(true)是多余的,多此一举。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值