1. Touch events are distributed from activity to layer
Always distributed to the focus control for processing
2. If the control's event-handling method returns True
The control consumes and continues to follow this event
Otherwise, the event is passed to the previous layer container of the control
3. The Ontouch method of the control's touch listener precedes
Ontouchevent execution of the control itself
How touch events are distributed and processed
Dispatchtouchevent
Onintercepttouchevent (only ViewGroup has this interception method)
Ontouchlistener.ontouch
Ontouchevent
Suppose an activity contains only one linearlayout, and this linearlayout contains a textview. As you can see from log,
When the user presses this textview, the order of the functions executed is:
Activity.dispatchtouchevent
Linearlayout.dispatchtouchevent
Linearlayout.onintercepttouchevent (LinearLayout is ViewGroup)
Textview.dispatchtouchevent
TextView.onTouchListener.onTouch
Textview.ontouchevent
LinearLayout.onTouchListener.onTouch
Linearlayout.ontouchevent
And finally the activity.ontouchevent.
The above is the case where each layer does not consume this touch event, that is, all methods return FALSE.
If either method consumes this event, it returns True, in which case the event is only to this method and the subsequent methods do not. Subsequent events will also be executed only to this method, that is, this method consumes and continues to pay attention to this event, such as: Move and lift, and other subsequent events.
Delivery and delivery of Android touch events