PtrClassicFrameLayout與viewpager橫向滑動衝突的問題

zz白龍發表於2018-03-21

最近遇到一個淡疼的bug,banner與下拉重新整理的ptr橫向滑動衝突,

    //左右滑動時重新整理控制元件禁止掉
    ptr.disableWhenHorizontalMove(true);

這樣寫有時候不好使,然後再加上重寫ptr

public class PtrClassicRefreshLayout extends PtrClassicFrameLayout {
    private boolean disallowInterceptTouchEvent = false;

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

    public PtrClassicRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public PtrClassicRefreshLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        disallowInterceptTouchEvent = disallowIntercept;
        super.requestDisallowInterceptTouchEvent(disallowIntercept);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent e) {
        switch (e.getAction()) {
            case MotionEvent.ACTION_UP:
                //解除重新整理的遮蔽
                this.requestDisallowInterceptTouchEvent(false);
                break;
        }

        if (disallowInterceptTouchEvent) {
            //事件向下分發給子控制元件,子控制元件會遮蔽掉父控制元件的重新整理
            return dispatchTouchEventSupper(e);
        }

        return super.dispatchTouchEvent(e);
    }
}

相關文章