android 事件分发

做个记录:
https://www.jianshu.com/p/238d1b753e64

 //如果子控件处理了事件,那么mFirstTouchTarget不为null
        if (actionMasked == MotionEvent.ACTION_DOWN
                || mFirstTouchTarget != null) {
            //disallowIntercept 一个不拦截的标记位
            //如果有这个标记位,则不拦截
            //如果没有,就去调用onInterceptTouchEvent来判断是否拦截
            //如果是ACTION_DOWN事件,那么disallowIntercept为false,因为之前有一个清空操作
            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.
            //代码进入这里,说明就两种情况。1.不是ACTION_DOWN事件 2.mFirstTouchTarget==null,
            // 这说明ACTION_DOWN事件已经拦截,那么接下来的事件都自己处理
            intercepted = true;
        }

你可能感兴趣的:(android 事件分发)