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,
- 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