Android为触摸事件封装了一个类:MotionEvent。
Activity所拥有的方法:
dispatchTouchEvent
onTouchEvent
ViewGroup所拥有的方法:
dispatchTouchEvent
onInterceptTouchEvent
onTouchEvent
View所拥有的方法:
dispatchTouchEvent
onTouchEvent
事件的传递:dispatchTouchEvent true:拦截,不继续,false:不拦截,继续流程。
事件的拦截:onInterceptTouchEvent
事件的处理:onTouchEvent true:处理了们不用审核,false:交给上级处理。
dispatchTouchEvent是事件分发的第一步,但是我们不太会改写这个方法,很多时候我们都是在onInterceptTouchEvent和onTouchEvent上做文章。
事件流程:传递,拦截,处理
Android中默认情况下事件传递是由最终的view的接收到,传递过程是从父布局到子布局,也就是从Activity到ViewGroup到View的过程。
Activity的dispatchTouchEvent()首先接收到ACTION_DOWN,执行super.dispatchTouchEvent(ev),事件向下分发。
如果dispatchTouchEvent()返回true,后续事件(ACTION_MOVE、ACTION_UP)会再传递;
如果dispatchTouchEvent()返回false,dispatchTouchEvent()就接收不到ACTION_UP、ACTION_MOVE。
参考文章:http://blog.youkuaiyun.com/xyz_lmn/article/details/12517911