本文参考摘取https://www.jianshu.com/p/38015afcdb58
一、基础知识
1、事件的类型
MotionEvent.ACTION_DOWN 按下(事件的开始)
MotionEvent.ACTION_UP 抬起(与DOWN对应)
MotionEvent.ACTION_MOVE 滑动
MotionEvent.ACTION_CANCEL 结束(非人为原因)
2、事件传递的对象
Activity ViewGroup View
3、事件传递的过程
从Activity -> ViewGroup --> View
4、事件分发设计的对象
dispatchTouchEvent() 分发事件
onInterceptTouchEvent() 拦截事件,仅ViewGroup由此方法
onTouchEvent() 处理点击事件
二、事件分发过程
1、Activity事件分发过程

方法总结

2、ViewGroup事件分发过程

核心方法总结

3、View事件分发机制

核心方法介绍

总结:
1、onTouch优先于onTouchEvent执行
网友评论