View事件体系

view dispatchTouchEvent()

12502        boolean result = false;
                  .....
12515        if (onFilterTouchEventForSecurity(event)) {
12516            if ((mViewFlags & ENABLED_MASK) == ENABLED && handleScrollBarDragging(event)) {
12517                result = true;
12518            }
12519            //noinspection SimplifiableIfStatement
12520            ListenerInfo li = mListenerInfo;
12521            if (li != null && li.mOnTouchListener != null
12522                    && (mViewFlags & ENABLED_MASK) == ENABLED
12523                    && li.mOnTouchListener.onTouch(this, event)) {
12524                result = true;
12525            }
12526
12527            if (!result && onTouchEvent(event)) {
12528                result = true;
12529            }
12530        }

OnTouchListener.onTouch()返回为true,那么onTouchEvent()就不会调用.
接着看onTouchEvent()

        13736    public boolean onTouchEvent(MotionEvent event) {
        13743        final boolean clickable = ((viewFlags & CLICKABLE) == CLICKABLE
        13744                || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)
        13745                || (viewFlags & CONTEXT_CLICKABLE) == CONTEXT_CLICKABLE;
        13746
        13747        if ((viewFlags & ENABLED_MASK) == DISABLED) {
        13748            if (action == MotionEvent.ACTION_UP && (mPrivateFlags & PFLAG_PRESSED) != 0) {
        13749                setPressed(false);
        13750            }
        13751            mPrivateFlags3 &= ~PFLAG3_FINGER_DOWN;
        13752            // A disabled view that is clickable still consumes the touch
        13753            // events, it just doesn't respond to them.
        13754            return clickable;
        13755        }
        13756        if (mTouchDelegate != null) {
        13757            if (mTouchDelegate.onTouchEvent(event)) {
        13758                return true;
        13759            }
        13760        }
        13761
        13762        if (clickable || (viewFlags & TOOLTIP) == TOOLTIP) {
        13763            switch (action) {
        13764                case MotionEvent.ACTION_UP:
        13765                    mPrivateFlags3 &= ~PFLAG3_FINGER_DOWN;
        13766                    if ((viewFlags & TOOLTIP) == TOOLTIP) {
        13767                        handleTooltipUp();
        13768                    }
        13769                    if (!clickable) {
        13770                        removeTapCallback();
        13771                        removeLongPressCallback();
        13772                        mInContextButtonPress = false;
        13773                        mHasPerformedLongPress = false;
        13774                        mIgnoreNextUpEvent = false;
        13775                        break;
        13776                    }
        13777                    boolean prepressed = (mPrivateFlags & PFLAG_PREPRESSED) != 0;
        13778                    if ((mPrivateFlags & PFLAG_PRESSED) != 0 || prepressed) {
        13779                        // take focus if we don't have it already and we should in
        13780                        // touch mode.
        13781                        boolean focusTaken = false;
        13782                        if (isFocusable() && isFocusableInTouchMode() && !isFocused()) {
        13783                            focusTaken = requestFocus();
        13784                        }
        13785
        13786                        if (prepressed) {
        13787                            // The button is being released before we actually
        13788                            // showed it as pressed.  Make it show the pressed
        13789                            // state now (before scheduling the click) to ensure
        13790                            // the user sees it.
        13791                            setPressed(true, x, y);
        13792                        }
        13793
        13794                        if (!mHasPerformedLongPress && !mIgnoreNextUpEvent) {
        13795                            // This is a tap, so remove the longpress check
        13796                            removeLongPressCallback();
        13797
        13798                            // Only perform take click actions if we were in the pressed state
        13799                            if (!focusTaken) {
        13800                                // Use a Runnable and post this rather than calling
        13801                                // performClick directly. This lets other visual state
        13802                                // of the view update before click actions start.
        13803                                if (mPerformClick == null) {
        13804                                    mPerformClick = new PerformClick();
        13805                                }
        13806                                if (!post(mPerformClick)) {
        13807                                    performClickInternal();
        13808                                }
        13809                            }
        13810                        }
        13811
        13812                        if (mUnsetPressedState == null) {
        13813                            mUnsetPressedState = new UnsetPressedState();
        13814                        }
        13815
        13816                        if (prepressed) {
        13817                            postDelayed(mUnsetPressedState,
        13818                                    ViewConfiguration.getPressedStateDuration());
        13819                        } else if (!post(mUnsetPressedState)) {
        13820                            // If the post failed, unpress right now
        13821                            mUnsetPressedState.run();
        13822                        }
        13823
        13824                        removeTapCallback();
        13825                    }
        13826                    mIgnoreNextUpEvent = false;
        13827                    break;

只要view的CLICKABLE和LONG_CLICKABLE有一个为true,那么她就会消耗事件,即onTouchEvent返回true,(和是否disable无关).当ACTION_UP事件发生时,触发performClick方法.

你可能感兴趣的:(View事件体系)