1. 程式人生 > >處理recycleview與viewpage的滑動衝突

處理recycleview與viewpage的滑動衝突

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
            y = ev.getY();
x = ev.getX();
getParent().requestDisallowInterceptTouchEvent(true);
            break;
        case MotionEvent.ACTION_MOVE:
            if (Math.abs
(ev.getX() - x) > Math.abs(ev.getY() - y)) getParent().requestDisallowInterceptTouchEvent(true); else getParent().requestDisallowInterceptTouchEvent(false); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: getParent().requestDisallowInterceptTouchEvent(false
); break; default: break; }
重寫ViewPage 覆蓋以上方法