The onInterceptTouchEvent() method is called whenever a touch event is detected on the surface of a ViewGroup, including on the surface of its children. If onInterceptTouchEvent() returns true, the MotionEvent is intercepted, meaning it will be not be passed on to the child, but rather to the onTouchEvent() method of the parent.
The onInterceptTouchEvent() method gives a parent the chance to see any touch event before its children do. If you return true from onInterceptTouchEvent(), the child view that was previously handling touch events receives anACTION_CANCEL, and the events from that point forward are sent to the parent's onTouchEvent() method for the usual handling. onInterceptTouchEvent() can also return false and simply spy on events as they travel down the view hierarchy to their usual targets, which will handle the events with their own onTouchEvent().
详情见:点击打开链接
本文详细解释了onInterceptTouchEvent()方法的作用及其实现机制。此方法允许父ViewGroup在子视图之前拦截触摸事件,如果返回true,则事件将被父视图处理,不再传递给子视图;若返回false,则事件将继续传递给子视图。
4368

被折叠的 条评论
为什么被折叠?



