首页 > 代码库 > 禁止RecycleView滑动

禁止RecycleView滑动

参考链接 http://stackoverflow.com/questions/30531091/how-to-disable-recyclerview-scrolling

public class CustomGridLayoutManager extends LinearLayoutManager {
 private boolean isScrollEnabled = true;

 public CustomGridLayoutManager(Context context) {
  super(context);
 }

 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();
 }
}

禁止滑动是调用setScrollEnabled(false);

再打开滑动是调用setScrollEnabled(false);

禁止RecycleView滑动