大家应该对Android Touch事件分发流程有了大致的了解,其中主要的分发对象包括
Activity:
在设备获取到事件之后首先流转到的既是Activity,如果在所有View都不处理Touch事件的情况下最后也是传回Activity处理
- 我们先来看Activity中的dispatchTouchEvent
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
onUserInteraction();
}
if (getWindow().superDispatchTouchEvent(ev)) {
return true;
}
return onTouchEvent(ev);
}
1.onUserInteraction() 在Activity中为空实现
2.getWindow().superDispatchTouchEvent(ev) windows的具体唯一实现PhoneWindow,所以去PhoneWindow查找superDispatchTouchEvent()
- PhoneWindow.java
@Override
public boolean superDispatchTouchEvent(MotionEvent event) {
return mDecor.superDispatchTouchEvent(event);
}
mDecor 即为DecorView,DecorView为一个FrameLayout,我们知道FrameLayout父类也为ViewGroup,所以到此就由Activity传到了ViewGroup中去了
public class DecorView extends FrameLayout
- 最后我们梳理一下Activity传递到ViewGroup的流程: