Android? Nestedscrolling and distribution mechanism? Two

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.