Android @ 事件分发机制

dispatchTouchEvent、onInterceptTouchEvent、onTouchEvent

MotionEvent ev;//down or move or up or others...
viewgroup.dispatchTouchEvent(ev);

public boolean dispatchTouchEvent(MotionEvent ev){
    boolean isConsumed = false;
    if(onInterceptTouchEvent(ev)){
        isCousumed = this.onTouchEvent(ev);
    }else{
        isConsumed = childView.dispatchTouchEvent(ev);
    }
    return isConsumed;
}

ViewGroup 中的相关源码:

public boolean dispatchTouchEvent(MotionEvent ev) {
    ......
    // Check for interception.
    final boolean intercepted;
    if (actionMasked == MotionEvent.ACTION_DOWN
            || mFirstTouchTarget != null) {
        final boolean disallowIntercept = (mGroupFlags & FLAG_DISALLOW_INTERCEPT) != 0;
        if (!disallowIntercept) {
            intercepted = onInterceptTouchEvent(ev);
            ev.setAction(action); // restore action in case it was changed
        } else {
            intercepted = false;
        }
    } else {
        // There are no touch targets and this action is not an initial down
        // so this view group continues to intercept touches.
        intercepted = true;
    }
    ......
}

参考:

  1. 十分钟彻底弄明白 View 事件分发机制
  2. 图解 Android 事件分发机制

未完成...

你可能感兴趣的:(Android @ 事件分发机制)