方案一:
public static void forceStopRecyclerViewScroll(RecyclerView mRecyclerView) {
mRecyclerView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_CANCEL, 0, 0, 0));
}
方案二:
1. publicclass CustomLinearLayoutManager extends LinearLayoutManager {
privatebooleanisScrollEnabled =true;
public CustomLinearLayoutManager(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
returnisScrollEnabled &&super.canScrollVertically();
}
}
2. CustomLinearLayoutManager linearLayoutManager =newCustomLinearLayoutManager(mContext);
linearLayoutManager.setScrollEnabled(false);
mDevicesRV.setLayoutManager(linearLayoutManager);
1