public boolean dispatchTouchEvent (MotionEvent ev)
Activity中解释:
Called to process touch screen events.You can override this to intercept all touch screen events before they aredispatched to the window. Be sure to call this implementation for touch screenevents that should be handled normally.
Parameters
ev |
The touch screen event. |
Returns
· boolean Return true if this event was consumed.
它会被调用处理触摸屏事件,可以重写覆盖此方法来拦截所有触摸屏事件在这些事件分发到窗口之前。通常应该处理触摸屏事件,一定要调用这个实现。当返回值为true时,表示这个事件已经被消费了。例如在TextActivity中dispatchTouchEvent在ACTION_MOVE返回true,运行结果如下:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-z5YKbaDp-1637305472132)(http://hunankeda110.iteye.com/admin/blogs/)]
也就是它并没有把那ACTION_MOVE分发下去。
public boolean onInterceptTouchEvent (MotionEvent ev)
Implementthis method to intercept all touch screen motion events. This allows you towatch events as they are dispatched to your children, and take ownership of thecurrent gesture at any point.
Usingthis function takes some care, as it has a fairly complicated interaction with [View.
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
onTouchEvent(MotionEvent)]( ),and using it requires implementing that method as well as this one in thecorrect way. Events will be received in the following order:
1. You will receive the down event here.
2. The down event will be handled either by a child of this viewgroup, or given to your own onTouchEvent() method to hand