您的位置:首页 > 其它

ScrollView嵌套RecyclerView时滑动出现的卡顿解决方案

2017-04-20 10:04 609 查看
问题现象:

一个界面有多个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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐