事件分发机制(理论基础篇)

2016-08-22  本文已影响8人  健康早餐

回顾

事件分发核心方法

  1. dispatchTouchEvent(MotionEvent me)
  2. onInterceptTouchEvent(MotionEvent me)
  3. onTouchEvent(MotionEvent me)

dispatchTouchEvent(MotionEvent me)

onInterceptTouchEvent(MotionEvent me)

onTouchEvent(MotionEvent me)

核心方法之间的关系

  // 事件分发
  public boolean dispatchTouchEvent(MotionEvent me){
        boolean consume=false;
        // 如果拦截事件对象
        if(onInterceptTouchEvent(ev)){
              // 调用onTouchEvent(ev)进行处理
              consume=onTouchEvent(ev);
        }else{
              // 向下分发
              consume=child.dispatchTouchEvent(ev);
        }
        return consume
  } 

流程梳理

ViewGroup如何处理事件

View如何处理事件

事件响应

上一篇 下一篇

猜你喜欢

热点阅读