Android event distribution, interception, processing

Source: Internet
Author: User

Event distribution
    • When the Android event is processed, it is slowly sent from the parent container to all relevant view according to the coordinates of the event.
    • So when you're not dealing with it, the flow chart for event delivery


Dispatchtouchevent returns True
    • But if we return true in the dispatchtouchevent of a, then the event is not distributed

    • The discovery only invokes the interception method of the Viewgroupa event, that is, the event is not distributed, even if its own Ontouchevent event is not processed
    • What if you let VIEWGROUPB's dispatchevent return true?

    • When the dispatchtouchevent of our view returns true? Now we can speculate on adispatchtouchevnet–>aonintercepttouchevent–>bdispatchtouchevent–>bonintercepttouchevent–. >cdispatchtouchevent

Onintercapttouchevent returns True
    • When our Viewgroupa Onintercepttouchevent returns True, our Viewgroupa decides to intercept the event.
    • As we know, when the event is intercepted and then directly into its own view of the TouchEvent method of processing,


    • The Onintercepttouchevent method is also where we resolve event conflicts when we write custom view

    • When our VIEWGROUPB's onintercepttouchevent returns true? The same principle


    • Of course, Onintercapttouchevent is the ViewGroup method, only ViewGroup can decide whether the event is intercepted, and our view has no Onintercepttouchevent method
Returns true in Ontouchevent
    • We know that returning true is the event is handled by our own view, then the event is consumed, how is the flowchart different?
    • Here we first let the ontouchevent of our view return True


    • What if we let our VIEWGROUPB deal with the incident? We can deduce that, too.

    • We can see from the print log that when we intercept the event, the next event is given directly to the VIEWGROUPB, which is also considered optimized

    • Next we'll be dealing with our event response by our top-level control, Viewgroupa, so what should be the effect?

    • As a result we can expect that the normal process will still go until our Viewgroupa Ontouchevent method is called, and the next event is directly handled by the control that handles the event.
#总的来说我们已经通过Log来详细的分析了事件的三个方法, now everyone should be clear about the time flow.
    • Summarize
      • When we return true in Dispatchtouchevent, the event will not be distributed
      • If we call Onintercepttouchevent to return True, then the event will be intercepted and given to the view handler of the interception event, and the Ontouchevent method will be called
      • If our ontouchevent returns True, then the event will be consumed, and the next event will not be passed down again, but instead be intercepted directly by the control of the event being handled, and then to the control that was just handling the event
      • In general, when we customize the view, we handle event collisions in the Onintercapttouchevent method to decide whether to intercept the event
      • And we will return true directly in Ontouchevent, indicating that if the child control is not processed, then our custom view will handle all events
      • View No Onintercapttouchevent method

Android event distribution, interception, processing

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.