Touch event transfer mechanism-ACTION_MOVE, ACTION_UP, and touch event Transfer Mechanism
To put it simply, when dispatchTouchEvent is distributing events, only the events ACTION_MOVE and ACTION_UP will be received if true is returned for the previous event (such as ACTION_DOWN.
DispatchTouchEvent and onTouchEvent can consume the event through return true to terminate the event transfer, while onInterceptTouchEvent cannot consume the event, which is equivalent to a cross port serving as a diversion function, ACTION_MOVE and ACTION_UP will be called in which functions, previously said that not a function received ACTION_DOWN, will receive ACTION_MOVE and other subsequent events.
1. In ViewGroup1, The dispatchTouchEvent method returns true to consume this event.
The ACTION_DOWN event is passed after (dispatchTouchEvent of the Activity) ---> (dispatchTouchEvent of ViewGroup1), and the event is consumed (such as the flow of the Red Arrow code ACTION_DOWN event ).
// Print the Log Activity | dispatchTouchEvent --> ACTION_DOWN ViewGroup1 | dispatchTouchEvent --> ACTION_DOWN ----> consumption
In this scenario, how does ACTION_MOVE and ACTION_UP look at the following logs?
Activity | dispatchTouchEvent --> ACTION_MOVE ViewGroup1 | dispatchTouchEvent --> ACTION_MOVE----TouchEventActivity | dispatchTouchEvent --> ACTION_UP ViewGroup1 | dispatchTouchEvent --> ACTION_UP
Medium
The red arrow indicates the flow direction of the ACTION_DOWN event.
The blue arrow represents the flow of ACTION_MOVE and ACTION_UP events.
2,We return true in the dispatchTouchEvent of ViewGroup2 to consume this event.
Activity | activities --> ACTION_DOWN ViewGroup1 | dispatchTouchEvent --> ACTION_DOWNViewGroup1 | consumed --> ACTION_DOWNViewGroup2 | consumed --> ACTION_DOWN ----> consumption Activity | consumed --> ACTION_MOVE ViewGroup1 | dispatchTouchEvent --> consumed | consumed --> events | dispatchTouchEvent --> ACTION_MOVE ---- TouchEventActivity | dispatchTouchEvent --> ACTION_UP ViewGroup1 | dispatchTouchEvent --> ACTION_UPViewGroup1 | actions --> ACTION_UPViewGroup2 | actions --> ACTION_UP
The red arrow indicates the flow direction of the ACTION_DOWN event.
The blue arrow represents the flow of ACTION_MOVE and ACTION_UP events.
3. ** we return true for the dispatchTouchEvent in the View to consume this event.
I will not draw a picture. The effect is similar to that of the dispatchTouchEvent return true in viewgroup2. Similarly, the dispatchTouchEvent function that receives ACTION_DOWN can receive both ACTION_MOVE and ACTION_UP. **
Therefore, we can basically conclude that if a control's dispatchTouchEvent returns true to consume the final event, the function that receives ACTION_DOWN can also receive ACTION_MOVE and ACTION_UP.
4,We return true in onTouchEvent of View to consume this event.
The red arrow indicates the flow direction of the ACTION_DOWN event.
The blue arrow represents the flow of ACTION_MOVE and ACTION_UP events.
5,The onTouchEvent in ViewGroup 2 returns true to consume this event.
The red arrow indicates the flow direction of the ACTION_DOWN event.
The blue arrow represents the flow of ACTION_MOVE and ACTION_UP events.
6,The onTouchEvent in ViewGroup 1 returns true to consume this event.
The red arrow indicates the flow direction of the ACTION_DOWN event.
The blue arrow represents the flow of ACTION_MOVE and ACTION_UP events.
7,We return true in the onTouchEvent of the Activity to consume this event.
The red arrow indicates the flow direction of the ACTION_DOWN event.
The blue arrow represents the flow of ACTION_MOVE and ACTION_UP events.
8,In View, the dispatchTouchEvent returns false and the onTouchEvent of the Activity returns true to consume this event.
The red arrow indicates the flow direction of the ACTION_DOWN event.
The blue arrow represents the flow of ACTION_MOVE and ACTION_UP events.
9,In View, dispatchTouchEvent returns false and onTouchEvent of ViewGroup 1 returns true to consume this event.
The red arrow indicates the flow direction of the ACTION_DOWN event.
The blue arrow represents the flow of ACTION_MOVE and ACTION_UP events.
10,We return false in View dispatchTouchEvent and return true in ViewGroup 2 to consume this event.
The red arrow indicates the flow direction of the ACTION_DOWN event.
The blue arrow represents the flow of ACTION_MOVE and ACTION_UP events.
11,We return false in dispatchTouchEvent of ViewGroup2 and return true in onTouchEvent of ViewGroup1 to consume this event.
The red arrow indicates the flow direction of the ACTION_DOWN event.
The blue arrow represents the flow of ACTION_MOVE and ACTION_UP events.
12,We return true in onInterceptTouchEvent of ViewGroup2 to intercept this event and return true in onTouchEvent of ViewGroup 1 to consume this event.
The red arrow indicates the flow direction of the ACTION_DOWN event.
The blue arrow represents the flow of ACTION_MOVE and ACTION_UP events.
I drew a lot of pictures at once, and I will not draw any more in several cases. I believe you will see the regular pattern. For onTouchEvent consumption events: In which View the onTouchEvent returns true, then, the ACTION_MOVE and ACTION_UP events will not be passed down after being uploaded from top to bottom, but will be passed directly to your onTouchEvent and end the event transfer process.
For the summary of ACTION_MOVE and ACTION_UP: the controls in which the ACTION_DOWN event is consumed (return true), The ACTION_MOVE and ACTION_UP events will be distributed from top to bottom (through dispatchTouchEvent) to the next, it will only be passed to this control and will not continue to be passed down. If the ACTION_DOWN event is consumed in dispatchTouchEvent, the event will be stopped so far. If the ACTION_DOWN event is consumed in onTouchEvent, the ACTION_MOVE or ACTION_UP event will be sent to the onTouchEvent of the control for processing and the transfer will end.