One of the Android event delivery mechanisms
Event delivery refers to the process of how a down, move,up event will be passed when multiple view overlays are in the same area in Android application development, and if the view is in the same region.
Suppose a viewgroup contains a view, and what methods ViewGroup and view trigger when the user presses the view.
Before we learn about these events, let's look at the concepts of several methods:
1. Dispatchtouchevent: This method only inherits the ViewGroup class, is the function that points to the Childview distribution event, that is, when the hand presses the position of view (or ViewGroup), All Childview events are distributed through dispatchtouchevent through the ViewGroup dispatchtouchevent event, which is the trigger before all view events are acquired.
2. Onintercepttouchevent: This method only inherits the ViewGroup class only, after Dipatchtouchevent distributes, will be captured by Onintercepttouchevent, this method acts as an interception event,
If this method is return true, the subsequent events are no longer processed. For example, when Oninterecpttouchevent is down and returns True, the event will not continue to be passed to the ontouchevent of the child view.
Instead, the event is passed to the current ViewGroup ontouchevent for processing
3.onTouchEvent: This method is available for both viewgroup and view because both ViewGroup and view are subclasses of view, so ontouchevent is a function of view.
Here is a concrete example to describe the event delivery process
Suppose a linearlayout contains a textview, when the user clicks on TextView, how the event will be passed (for convenience of description, respectively, using L1,T1)
1. If the event is passed by default in the following order
L1 dispatchtouchevent down and L1 oninterecpttouchevent down->t1 ontouchevent, by default this is the order of delivery
- If T1 's Ontouchevent's down return is false , then the event disappears and no longer continues to pass.
- If T1 's ontouchevent is down to true , then the event will be passed to L1 ontouchevent, so the event has the following process
- L1 's dispatchtouchevent down, L1 's oninterecpttouchevent down->t1 Ontouchevent's->l1 down ontouchevent
2. So we can draw a conclusion
- If the ontouchevent of the child view returns True, the down event will no longer continue to pass down, and if the child view's Ontouchevent returns false, the down continues to be passed to Childview The ontouchevent of the parent
The up event does not go down the ontouchevent pass of the event, who handles the ontouchevent down event and returns True (then the event no longer continues to pass), and who processes the up event, So if the down event is passed to the top-level Parentview, and the ontouchevent of the top-level parent view returns FALSE, the program loses the UP event.
One of the event passes (basic concept)