The illustration
As shown below, there are three layers, Activity, ViewGroup and View from top to bottom. Events are dispatched from the Activity’s dispatchTouchEvent, with the top word of the arrow representing the method return value.
Touch event distribution core
The dispatch of events between views is essentially a big recursive function, and that recursive function is the dispatchTouchEvent method. In this recursive process, if there is a ViewGroup, onInterceptTouchEvent is called in real time to intercept the event, or the onTouchEvent method is called to handle the event.
Pay attention to
ACTION_MOVE and ACTION_UP will be sent from the top down (via dispatchTouchEvent) to the control where the ACTION_DOWN event is consumed (return true). If the ACTION_DOWN event is consumed at dispatchTouchEvent, then the event stops being delivered. If the ACTION_DOWN event is consumed on onTouchEvent, the ACTION_MOVE or ACTION_UP event is passed to the control’s onTouchEvent handler and the transfer ends.
CANCEL event trigger scenario: When the parent View does not intercept and then intercepts again in the MOVE event, the child View will receive a CANCEL event.
OnTouch () >onTouchEvent () >onClick ()