Picture will talk series of Android events distribution delivery mechanism

Source: Internet
Author: User

in some complex layouts, there are often issues such as event collisions, event failures, and so on, which requires an in-depth understanding of Android the distribution delivery mechanism for the event. The best way is to write a demoyourself, print the event-related logs to see its running process, and then combined with the source to understand deeply. Of course there is no such thing here, there is only a summary of things, if you like this kind of things, then please continue to look down.

The usual, first:


user interaction typically occurs on the touchscreen, so the transmission of the Android event will inevitably involve viewgroup and View, ViewGroup with the View the methods involved in handling event delivery are as follows:  

ViewGroup:

<span style= "FONT-SIZE:14PX;" >public boolean dispatchtouchevent (Motionevent event) Public boolean ontouchevent (Motionevent event) Public boolean Onintercepttouchevent (Motionevent event) </span>

View:

<span style= "FONT-SIZE:14PX;" >public boolean dispatchtouchevent (Motionevent event) Public boolean ontouchevent (Motionevent event) </span>


where dispatchtouchevent is responsible for event distribution,ontouchevent is responsible for event handling,onintercepttouchevent responsible for event interception. As you can see, only viewgroup has the onintercepttouchevent method.

After understanding the basic methods of event correlation, take a look at some key points:

1.Android Event Delivery order:Activity--->viewgroup--->view.

2. If trueis returned in dispatchtouchevent , thedistribution is no longer continued, the event is canceled , and falseis returned. The event is passed on.

3. If viewgroup onintercepttouchevent return true The interception event is not passed down to the view viewgroup self-processing; if you return false view

4. If ontouchevent returns true, it indicates that it consumes the event but does not respond to onclicklistener; false, it will continue to respond to onclicklistenerIf it has been set.

5. The other can be referenced in the specific description.



Picture will talk series of Android events distribution delivery mechanism

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.