Android-developed friends often deal with a variety of touch events, but in the process of touching events, there are three main methods: Dispatchtouchevent (), Onintercepttouchevent (), and ontouchevent (). Believe that this troubled a lot of friends, the following through the text to you about the transfer process between them.
Tools/Materials
Method/Step
- 1
The origin of the event:
We all know that touch events start with the Dispatchtouchevent method of activity. The super.dispatchtouchevent (EV) of the parent class is called again, and the event is dispatched.
- 2
ViewGroup vs. View: View is the simplest class for Android controls, and all controls inherit view directly or indirectly, that is, ViewGroup inherits view. View has two callback functions Dispatchtouchevent and Ontouchevent;viewgroup have three callback functions dispatchtouchevent, Ontouchevent and Onintercepttouchevent.
- 3
Dispatchtouchevent Event Description:
Dispatchtouchevent is only responsible for handling the distribution of touch events, which begins with the dispatchtouchevent of the activity. The parent class is then executed
The Super.dispatchtouchevent (EV) event is distributed downward.
- 4
Onintercepttouchevent Event Description:
Onintercepttouchevent is a method provided by ViewGroup, which returns false by default to indicate that an event is not intercepted and when True indicates that the event was intercepted, which means that it handles consumption itself.
- 5
Ontouchevent Event Description:
ViewGroup and view have this method, ontouchevent this method mainly handles the touch event of the press move and bounce operation, when the return to true indicates consumption of this event, false is not consumed, that is, return to the previous layer of processing.
- 6
The delivery process of the event:
The delivery of events in Android is passed from the parent layout to the child layout, the parent layout can have many, that is, the process of Viewgroup-->viewgroup-->view, ViewGroup is a pass-through effect.
An explanation of the Android touch event delivery mechanism