Android touch event delivery diagram
This blog post explains the process
Introduction to touchevent related events flow chart decomposition, explanation, summary and induction
1、 Introduction to touchevent related events
Android touchevent related events include 1 dispatchtouchevent. This method is used to distribute touchevent. 2 onintercepttouchevent. This method is used to intercept touchevent. 3 ontouchevent method is used to process touchevent
A special point is the onintercepttouchevent event. There is no such event in the activity and view, because the activity itself is only a container or carrier, and there is no event interception. The view itself is the smallest unit or subclass of an event, and there is no subclass event that can be intercepted, so they have no onintercepttouchevent event, There are only dispatchtouchevent and ontouchevent events.
2、 Explanation of flow chart decomposition
In order to better understand the whole transmission mechanism of touch events, I drew a flow chart according to event transmission to help you understand.! [write picture description here]
This figure mainly includes three layers, namely activity ViewGroup view, which is passed level by level according to the transmission of events. There are several important points to note. 1. If dispatchtouchevent handles this event,
Then his execution order is like this. This is the dispatchtouchevent of the ViewGroup that handled this event. 2. Ontouchevent if the touchevent of the child view does not handle this event, the event will be passed up in turn until someone handles it. If it is passed all the way to the ontoucheevent of the activity and no one handles it, the event will be ended by default
Core code
1. Activity
2.viewGroup
3.view
The above is only part of the code, but all events are listed.
Summary and induction
Through the above learning, we should be able to more deeply understand the event transmission mechanism, but we may not use it all in the actual development process, but we must know its operation transmission principle, so that there will be no jam in case of special business needs. In the actual development, we can meet the needs as long as we rewrite the ontouchevent event event, But if we want to rewrite other events, we must be more considerate and involve more.
Demo point here
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.