Android View event Delivery

Source: Internet
Author: User

Welcome reprint, please attach Source:
http://blog.csdn.net/as02446418/article/details/47422891

1. Basic knowledge

(1) All touch events are encapsulated as motionevent objects, including touch location, time, history, and the first few fingers (multi-fingered touch).

(2) The event types are divided into Action_down, action_up, Action_move, Action_pointer_down, Action_pointer_up, Action_cancel, and each event is ACTION_ Down starts action_up end.

(3) The handling of events consists of three categories, namely, passing--dispatchtouchevent () functions, intercepting--onintercepttouchevent () functions, consuming--ontouchevent () functions, and Ontouchlistener

2. Delivery process

(1) The event is passed from Activity.dispatchtouchevent (). Just do not stop or intercept, from the top view (ViewGroup) started down (sub view) passed. The child View can handle the event through Ontouchevent ().

(2) The event is passed by the parent View (ViewGroup) to the child View,viewgroup to intercept the event by Onintercepttouchevent () and stop it from passing down.

(3) Assume that the event from the top down the process has not been stopped, and the bottom of the sub-view no consumption events, the event will be anti-yearning to pass, then the parent View (viewgroup) can be consumed, assuming still not be consumed. The Ontouchevent () function of the Activity is finally reached.

(4) Assuming that the View does not consume the action_down, then other events will not be passed over.

(5) Ontouchlistener takes precedence over ontouchevent () to consume the event.
The above consumption means that the corresponding function return value is true.

many others please read the original PDF in English : Mastering the Android Touch System

Demo Sample code:[email protected]

We enclose two flow charts in the original text:
(1) View does not handle event flowchart


(2) View processing event flowchart

3. Finally, say a few words

Android Touch Event
Assume that the layout hierarchy is
Layout0
Layout1
Layout2
Layout3

Suppose no one has gone to Intercepttouch, and at the same time no one has dealt with the Ontouch event.


So layout0->intercept layout1->intercept layout2->intercept layout3->intercept
Layout3->ontouch Layout2->ontouch Layout1->ontouch Layout0->ontouch
Since no one has consumed the Action_down incident, perhaps the Move,up event will not be passed in.

Suppose Layout2 intercept, but not consume Ontouch
So layout0->intercept layout1->intercept layout2->intercept
Layout2->ontouch Layout1->ontouch Layout0->ontouch
Maybe events won't pass in

Suppose Layout2 intercept, spending at the same time.
So 0->intercept 1->intercept 2->intercept 2->ontouch
0->intercept 1->intercept 2->ontouch
0->intercept 1->intercept 2->ontouch
0->intercept 1->intercept 2->ontouch

Suppose the Layout2 intercept. No consumption, Layout1 consumption.
So 0->intercept 1->intercept 2->intercept
2->ontouch 1->ontouch
0->intercept 1->ontouch
0->intercept 1->ontouch
0->intercept 1->ontouch

Sum up.

Law is
Assuming that the current layout is intercept, neither the child view nor the child viewgroup have a chance to get a touch event.

Assuming that the current layout does not consume events, the event will continue to bubble up until the ontouchevent of a parent layout consumes the event.

Assuming that no one parent layout consumes this event, the event will not be accepted.
Suppose that there is a layout that consumes this event during the bubbling process. Then the intercept of all the parent layout of this layout will still be called. However, the current layout of the intercept will not be called again.

Call the Ontouch event directly.

In addition, for the underlying view, there is a way to block the parent layer's view interception touch event, which is called GetParent (). Requestdisallowintercepttouchevent (True); Once the underlying view receives the touch action and calls this method, the parent view will no longer invoke onintercepttouchevent, nor can it intercept the subsequent action. In practice, it is found that the ListView calls this method when scrolling.

So that the action cannot be intercepted.

Android View event Delivery

Related Article

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.