android:30 minutes to figure out the touch event distribution mechanism
This reprint of Android in Dispatchtouchevent (), Onintercepttouchevent () and ontouchevent ()
in the next chapter, the four methods related to nestedscrolling are summarized and analyzed!
then use two demos to distribute the view events before 5.0, respectively, and nestedscrolling use for different implementations!
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 Yes viewgroup provides methods, The default returns FALSE, which returns true for interception.
ontouchevent
view, There are two callback functions :
1 Public Boolean dispatchtouchevent (motionevent ev);
2 Public Boolean ontouchevent (motionevent ev);
in ViewGroup, there are three callback functions :
3 Public Boolean dispatchtouchevent (motionevent ev);
4 Public Boolean onintercepttouchevent (motionevent ev);
5 Public Boolean ontouchevent (motionevent ev);
In activity, there are two callback functions:
6 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 for subsequent events (Action_move, Action_up) will be passed again if the return false,dispatchtouchevent () is not receivedaction_up, Action_move.
The following pictures refer to the[EoE]
Figure 1. Action_down was not consumed .
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 at the outset
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.
From for notes (Wiz)
Android? Nestedscrolling and distribution mechanism? Two