您现在的位置是:首页 > 文章详情

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

日期:2018-06-05点击:947
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)是多余的,多此一举。
原文链接:https://yq.aliyun.com/articles/615651
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章