ScrollView嵌套RecyclerView时滑动出现的卡顿解决方案
2017-04-20 10:04
609 查看
问题现象:
一个界面有多个RecyclerView或者其他超过一屏显示的一些内容时,就需要要上下滚动了,就会需要在外面嵌套一个ScrollView,但是滑动过程不是很顺畅,有卡顿的感觉。
解决方案:
禁止RecyclerView的滑动。
最简单便捷的方法就是
另外就是重写LayoutManager了,以Grid模式举例说明:
public class ScrollGridLayoutManager extends GridLayoutManager {
private boolean isScrollEnabled = true;
public ScrollGridLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public ScrollGridLayoutManager(Context context, int spanCount) {
super(context, spanCount);
}
public ScrollGridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) {
super(context, spanCount, orientation, reverseLayout);
}
public void setScrollEnabled(boolean flag) {
this.isScrollEnabled = flag;
}
@Override
public boolean canScrollVertically() {
//Similarly you can customize "canScrollHorizontally()" for managing horizontal scroll
return isScrollEnabled && super.canScrollVertically();
}
}
一个界面有多个RecyclerView或者其他超过一屏显示的一些内容时,就需要要上下滚动了,就会需要在外面嵌套一个ScrollView,但是滑动过程不是很顺畅,有卡顿的感觉。
解决方案:
禁止RecyclerView的滑动。
最简单便捷的方法就是
linearLayoutManager = new LinearLayoutManager(context) { @Override public boolean canScrollVertically() { return false; } };
另外就是重写LayoutManager了,以Grid模式举例说明:
public class ScrollGridLayoutManager extends GridLayoutManager {
private boolean isScrollEnabled = true;
public ScrollGridLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public ScrollGridLayoutManager(Context context, int spanCount) {
super(context, spanCount);
}
public ScrollGridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) {
super(context, spanCount, orientation, reverseLayout);
}
public void setScrollEnabled(boolean flag) {
this.isScrollEnabled = flag;
}
@Override
public boolean canScrollVertically() {
//Similarly you can customize "canScrollHorizontally()" for managing horizontal scroll
return isScrollEnabled && super.canScrollVertically();
}
}
相关文章推荐
- Android ScrollView里嵌套RecyclerView时,在RecyclerView上滑动时出现卡顿(冲突)的现象
- NestedScrollview 嵌套 RecyclerView 滑动卡顿,ScrollView 嵌套 RecyclerView 冲突 解决方案
- ScrollView里嵌套RecyclerView时,在RecyclerView上滑动时出现卡顿(冲突)的现象
- 解决ScrollView嵌套RecyclerView时滑动出现的卡顿
- ScrollView嵌套RecyclerView时滑动出现的卡顿,禁止RecyclerView的滑动
- ScrollView中嵌套RecyclerView滑动卡顿的问题
- 解决ScrollView嵌套RecyclerView 滑动卡顿和嵌套多个RecyclerView 显示不全的问题
- NestedScrollview 嵌套 RecyclerView出现滑动冲突解决方法
- 解决ScrollView嵌套RexyclerView导致6.0以上手机ScrollView和RecyclerView可以同时滑动问题,5.1手机滑动卡顿问题(解决一个另一个又出现)
- 解决ScrollView嵌套RecyclerView 滑动卡顿和嵌套多个RecyclerView 显示不全的问题
- Android Scrollview嵌套RecyclerView导致滑动卡顿问题解决
- ScrollView中嵌套RecycleView出现的不显示,显示不全及滑动卡顿及ScrollView禁止滚动到中间
- NestedScrollView中嵌套ViewPager或RecyclerView出现滑动冲突的解决
- Android解决RecyclerView嵌套RecyclerView滑动卡顿
- ScrollView 嵌套 RecyclerView 滑动到底端 在滑动的时候出现卡顿(绝对管用)
- 解决5.0以上系统ScrollView嵌套RecyclerView滑动迟缓
- android ScrollView 嵌套RecyclerView 快速滑动粘黏问题
- 【Android】ListView、RecyclerView、ScrollView里嵌套ListView 相对优雅的解决方案:NestFullListView
- RecyclerView 瀑布流 嵌套ScrollView解决方案
- android ScrollView 嵌套RecyclerView 解决滑动冲突