Android Touch事件的分发机制
Touch事件的分发机制 网上很多用源码来分析touch事件机制的文章,但是由于View和ViewGroup事件分发和android系统事件分开有关系,所以看起来有点云里雾里的,下面自己写了一个例子来说嘛touch分发的原理,和我们工作中遇到此类问题应该怎么处理这类事件,首先必须知道的一点是ViewGroup是继承至ViewG的,这个你们可以去源码中看看,接下来我们来说明ViewGroup和View下的三个相关Touch分发的函数 dispatchTouchEvent() : 该方法用于touch事件的分发, view和viewgroup都实现了该方法 onTouchEvent() : 该方法就是用于具体的touch事件处理,这个方法实现在View中。 onInterceptTouchEvent() : 该方法用于拦截touch事件,这个方法只有ViewGroup有。 接下来我们先看看源码中的官方说明: /** * Pass the touch screen motion event down to the target view, or this * view if it is the target. * * @param event The motion event to be dispatched. * @return True if the event was