1. 程式人生 > >禁止RecycleView滑動

禁止RecycleView滑動

manage true near 參考 over view ear ble com

參考鏈接 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滑動