Android 事件分发机制面试详解
2017-12-05 本文已影响94人
千涯秋瑟
Android事件分发机制详解:史上最全面、最易懂
一、为什么会有事件分发机制


Android用一个32位的整型值表示一次TouchEvent事件,低8位表示touch事件的具体动作,比如按下,抬起,滑动,还有多点触控时的按下,抬起.
二、三个重要的事件分发的方法

事件分发业务流程说明图

其中:
super:调用父类方法
true:消费事件,即事件不继续往下传递
false:不消费事件,事件也不继续往下传递 / 交由给父控件onTouchEvent()处理
三者之间的关系


Activity 中的dispatchTouchEvent()方法,然后调用的PhoneWindow superDispatchTouchEvent方法。

PhoneWindow中的superDispatchTouchEvent方法,它又调用的DevorView的superDispatchTouchEvent方法。

DevorView中的superDispatchTouchEvent方法,调用ViewGroup的dispatchTouchEvent方法
