The distribution and consumption mechanism of Touch events under Android programming

Source: Internet
Author: User

First, Touch incident analysis


***************************************************************************************************************
Event Distribution: Public boolean dispatchtouchevent (motionevent ev)

When the Touch event occurs, the Dispatchtouchevent (motionevent ev) method of the Activity passes the event to the outermost layer by tunneling (passing from the root element down to the topmost child element or in an intermediate element because a condition stops passing). View's dispatchtouchevent (motionevent ev) method, and the event is distributed by the view's dispatchtouchevent (Motionevent ev) method. The event distribution logic for Dispatchtouchevent is as follows:

If return true, the event is distributed to the current View and consumed by the Dispatchtouchevent method, while the event stops passing down;
If return is false, event distribution is divided into two scenarios:
If the current View gets events directly from the activity, the event is returned to the activity's ontouchevent for consumption;
If the current view gets an event from the outer parent control, the event is returned to the parent view's ontouchevent for consumption.
If the system default super.dispatchtouchevent (EV) is returned, the event is automatically distributed to the current View's Onintercepttouchevent method.

***************************************************************************************************************
Event interception: Public boolean onintercepttouchevent (motionevent ev)

When the dispatchtouchevent (motionevent ev) method of the outer view returns to the system's default super.dispatchtouchevent (EV) case, the event is automatically distributed to the current view's Onintercepttouchevent method. The Onintercepttouchevent event interception logic is as follows:

If Onintercepttouchevent returns True, the event is intercepted and the intercepted event is referred to the current View's ontouchevent for processing;
If Onintercepttouchevent returns FALSE, the event is released, the event on the current view is passed to the child view, and then the dispatchtouchevent of the view begins the distribution of the event;
If Onintercepttouchevent returns super.onintercepttouchevent (EV) and returns false as the processing logic.

***************************************************************************************************************
Event Response: Public boolean ontouchevent (motionevent ev)

The Dispatchtouchevent returns super.dispatchtouchevent (EV) and onintercepttouchevent returns TRUE or returns Super.onintercepttouchevent ( EV), the ontouchevent will be called. The event response logic for Ontouchevent is as follows:

If the event is passed to the current view's Ontouchevent method, and the method returns False, the event is passed up from the current view and is received by the ontouchevent of the upper view, if passed to the ontouchevent above Also returns false, the event "disappears" and the next event is not received.

If True is returned, the event is received and consumed.
If the return super.ontouchevent (EV) default handles the logic of the event and returns false, the same.

The distribution and consumption mechanism of Touch events under Android programming

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.