美文网首页
关闭RecyclerView 滑动

关闭RecyclerView 滑动

作者: Il_mondo | 来源:发表于2018-07-06 14:30 被阅读3次
/**
 * 开启或关闭滑动
 */
public class CustomLinearLayoutManager extends LinearLayoutManager {
    private boolean isScrollEnabled = true;

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

    public CustomLinearLayoutManager(Context context, boolean isScrollEnabled) {
        super(context);
        this.isScrollEnabled = isScrollEnabled;
    }

    public CustomLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
        super(context, orientation, reverseLayout);
    }

    public CustomLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public void setScrollEnabled(boolean flag) {
        this.isScrollEnabled = flag;
    }

    @Override
    public boolean canScrollVertically() {
        int orientation = getOrientation();
        if (orientation == LinearLayoutManager.VERTICAL) {
            return isScrollEnabled && super.canScrollVertically();
        }
        return super.canScrollVertically();
    }

    @Override
    public boolean canScrollHorizontally() {
        int orientation = getOrientation();
        if (orientation == LinearLayoutManager.HORIZONTAL) {
            return isScrollEnabled && super.canScrollHorizontally();
        }
        return super.canScrollHorizontally();
    }
}

相关文章

网友评论

      本文标题:关闭RecyclerView 滑动

      本文链接:https://www.haomeiwen.com/subject/viavuftx.html