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)是多余的,多此一举。 
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Android Studio 3.0 解决Gradle长时间同步
问题描述 每次进入项目后,Gradle都进行长时间的同步,大约同步时间都有20分钟吧 解决办法 将项目根目录下的build.gradle文件中的google()仓库注释,此处有两处需要注释 解决办法.png
- 下一篇
Architecture -- WorkManager
1. WorkManager 1). 简介 其实就是"管理一些要在后台工作的任务, -- 即使你的应用没启动也能保证任务能被执行",WorkManager在底层, 会根据你的设备情况, 选用JobScheduler, Firebase的JobDispatcher, 或是AlarmManager。WorkManager并不是为了那种在应用内的后台线程而设计出来的. 这种需求你应该使用ThreadPool。 2). 引入 kolin # Android Studio 3.0, 3.0以下版本请使用complie ext.work_version = "1.0.0-alpha02" // WorkManager implementation "android.arch.work:work-runtime:$work_version" // use -ktx for Kotlin // optional - Firebase JobDispatcher support implementation "android.arch.work:work-firebase:$work_version" ...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- SpringBoot2更换Tomcat为Jetty,小型站点的福音
- SpringBoot2整合Redis,开启缓存,提高访问速度
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- CentOS7,CentOS8安装Elasticsearch6.8.6
- CentOS6,CentOS7官方镜像安装Oracle11G