问题现象:
一个界面有多个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(); } }