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()
.
详情见:点击打开链接