ontouchevent浅谈

    xiaoxiao2025-06-13  15

    同一事件序列的概念:以down开始,up为止,中间包含若干个move;

    返回值如果为true,表示消耗此事件,同一事件序列都在此view上进行。

    返回值为false 表示不拦截,会向下传递(子View)。

    ==============================================================

    ontouchlistener 的优先级高于(重写)onTouchEvent(MotionEvent event)。

    也就是说如果一个view同时设置了ontouchlistener和重写了onTouchEvent(MotionEvent event),当ontouchlistener返回true(拦截),那么onTouchEvent将不会被调用。如果ontouchlistener返回(false)那么onTouchEvent将会被调用,因为ontouchlistener 的优先级高于onTouchEvent(MotionEvent event)。

    ==============================================================

    super.onTouchEvent(event)为默认返回值。 View默认返回值为true(拦截)。 但是,如果他的clickable 和longClickable属性同时为false,则默认返回值为false。 longClickable的默认属性都为:false。例如:1、View 继承Button他的clickable属性默认就true, 所以super.onTouchEvent(event)为true;2、View 继承TextView他的clickable属性默认就false, 所以super.onTouchEvent(event)为false;

    ==============================================================

    ViewGroup默认不拦截任何事件super.onTouchEvent(event)的默认返回值为false。

    例如:ListView继承ViewGroup, 如果将 onTouchEvent(MotionEvent event) 返回值设为true,那么将不能滑动和调用点击item事件,使用时要注意!

    转载请注明原文地址: https://ju.6miu.com/read-1299889.html
    最新回复(0)