Dispatchtouchevent (), Onintercepttouchevent (), and Ontouchevent () in Android

Source: Internet
Author: User

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

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.