欢迎来到皮皮网网首页

【城市源码下载】【Windows 10系统源码】【iapp源码分享网站】android touch 源码

来源:解析器源码 时间:2024-11-28 20:06:33

1.android onTouchEvent和setOnTouchListener中onTouch的区别
2.Android onTouchEvent和setOnTouchListener中onTouch的区别

android touch 源码

android onTouchEvent和setOnTouchListener中onTouch的区别

       åœ¨dispatch过程中会先去check已经被set的OnTouchListener,如果在OnTouchListener的onTouch里头return true了,就会直接return true,不再走view本身的onTouchEvent。具体看代码:

        /

**

        * Pass the touch screen motion event down to the target view,源码城市源码下载 or this

        * view if it is the target.

       

*

        * @param event The motion event to be dispatched.

        * @return True if the event was handled by the view, false otherwise.

        */

        public boolean dispatchTouchEvent(MotionEvent event) {

        if (mInputEventConsistencyVerifier != null) {

        mInputEventConsistencyVerifier.onTouchEvent(event, 0);

        }

        if (onFilterTouchEventForSecurity(event)) {

        //noinspection SimplifiableIfStatement

        ListenerInfo li = mListenerInfo;

        if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED

        && li.mOnTouchListener.onTouch(this, event)) {

        return true;

        }

        if (onTouchEvent(event)) {

        return true;

        }

        }

        if (mInputEventConsistencyVerifier != null) {

        mInputEventConsistencyVerifier.onUnhandledEvent(event, 0);

        }

        return false;

        }

Android onTouchEvent和setOnTouchListener中onTouch的区别

       onTouchEvent是用来监听整个屏幕的滚动,setOnTouchListener是监听某个控件的。但setOnTouchListener监听最外层布局的滚动时,他们的就一样了。