Presumably you will sometimes encounter the need to customize the control bar, this time will encounter the transmission and processing of events, very cumbersome Ah! Baidu above a ticket on the transmission mechanism of the event, but all the same, are dispatchtouchevent
Returns True, the event is intercepted, false is distributed to the child control, and so on, after several days of research found that this event is not said to be so simple and not imagined difficult.
General Click events, sliding events are made up of action_up, Action_moe, Action_down , Android apps by default, touch events are transferred from the activity, Assuming that the view does not need to intercept the event, then this touch event will walk around the inside of the view and back to the activity, if we are bound to a view of an event listener, then this event can only be consumed by a view.
In fact, we generally know the above, but when it is necessary to rewrite a control when it will be puzzled, because the light know that the above is not enough, this time we need to look at the source of research, through my tinker, found the law of event transmission:
Activity Delivery Order:dispatchtouchevent → event pass to Window→window passed to the inside of the view→view Dispatchtouchevent
ViewGroup Order of delivery:dispatchtouchevent →onintercepttouchevent→ event is passed to the next layer →ontouchevent
dispatchtouchevent return to Ture, then this event will not go back, because the next layer was intercepted, The Ontouchevent method is only last called in the dispatchtouchevent, because the event is passed to the next layer, if the next layer is not executed to call ontouchevent this step, and onintercepttouchevent only ViewGroup, is the event of another interception. < Span style= "font-size:12px" >
This is the system default, but if you rewrite the dispatchtouchevent method above, you can subvert the default rule, such as ViewGroup passed to its child view, I return false in their related event interception method, and then to each of them to deal with their own events, then it is not an event can only be consumed by a view, temporarily on the water to this, it is only a bit of their own experience, Welcome to learn from each other Exchange
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Talking about the mechanism of Android event transmission