The Dispatchtouchevent (), Onintercepttouchevent (), and Ontouchevent () methods are most important in the touch event delivery process in Android. This is one of the problems that bothers beginners, and I started too. This records the process of Dispatchtouchevent (), Onintercepttouchevent (), and Ontouchevent () for memory.
Dispatchtouchevent is handling touch event distribution, and events (in most cases) start with the dispatchtouchevent of the activity. Perform
Super.dispatchtouchevent (EV), the event is distributed downward.
Onintercepttouchevent is the method provided by the ViewGroup, which returns false by default and returns true to indicate interception.
Ontouchevent is the method provided in view, ViewGroup also has this method, Onintercepttouchevent is not available in view. The default returns true in view, which indicates consumption of this event.
In view, there are two callback functions:
Public Boolean dispatchtouchevent (motionevent ev);
Public Boolean ontouchevent (motionevent ev);
In ViewGroup, there are three callback functions:
Public Boolean dispatchtouchevent (motionevent ev);
Public Boolean onintercepttouchevent (motionevent ev);
Public Boolean ontouchevent (motionevent ev);
In activity, there are two callback functions:
Public Boolean dispatchtouchevent (motionevent ev);
Public Boolean ontouchevent (motionevent ev);
By default in Android, event delivery is received by the final view, and the delivery process is from the parent layout to the child layout, that is, from activity to ViewGroup to view, by default, ViewGroup is the pass-through function. The event delivery process in Android (in the direction of Arrows), as shown in [Qiushuiqifei], thanks to [Qiushuiqifei] finishing.
Touch events are a series of action_down,action_move. MOVE ... MOVE, last action_up, touch events, and Action_cancel events. Events begin with Action_down, and the activity's dispatchtouchevent () first receives Action_down, executes super.dispatchtouchevent (EV), and distributes the events down.
Dispatchtouchevent () returns True, subsequent events (Action_move, action_up) are passed again, and if the return False,dispatchtouchevent () is not received action_up, the ACTION _move.
The following images are referenced from [EoE]
Figure 1. Action_down was not consumed.
Figure 2-1. Action_down was consumed by the view
Figure 2-2. Subsequent action_move and up will look for the view without being intercepted.
Figure 3. The follow-up was intercepted.
Figure 4action_down was intercepted from the start
The touch events in Android start with Action_down:
Single finger operation: Action_down---action_move----action_up
Multi-finger operation: Action_down---action_pointer_down---action_move--action_pointer_up---action_up.
Dispatchtouchevent (), Onintercepttouchevent (), and Ontouchevent () in Android