RecyclerView的滑动事件禁止问题
网上不太负责的朋友随便抛一句recyclerview.setNestedScrollingEnabled(false);
但是请注意,setNestedScrollingEnabled(false)只适用于NestedScrollingChild的子类,简单来说就只适用于嵌套布局,否则是无效的。
现在推出工具类:
import android.content.Context; import android.support.v7.widget.GridLayoutManager; import android.util.AttributeSet; public class CustomLinearLayoutManager extends GridLayoutManager { private boolean isScrollEnabled = true; public CustomLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public CustomLinearLayoutManager(Context context, int spanCount) { super(context, spanCount); } public CustomLinearLayoutManager(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() { return isScrollEnabled && super.canScrollVertically(); } }
调用:
CustomLinearLayoutManager customLinearLayoutManager = new CustomLinearLayoutManager(mContext,3); customLinearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); //展示效果为何一样? customLinearLayoutManager.setScrollEnabled(false); rvPictureBookHead.setLayoutManager(customLinearLayoutManager);