http://www.jianshu.com/p/e99b5e8bd67b
http://blog.csdn.net/guolin_blog/article/details/9097463
In Android development, the event distribution mechanism is an important knowledge system of Android, understanding and familiar with the entire distribution mechanism to better analyze the various click-slip failures, better to extend the control of the event function and develop custom controls, At the same time the event distribution mechanism is also one of the Android interview must be asked, if you can put some of the following event distribution map on the spot to draw a lot of certainly. Needless to say, a summary: The event distribution mechanism is very important.
Looking at a few summaries, I think it's better to start with a general framework to understand
Action_down
1, if the event is not interrupted, the entire event flow is a kind of U-shape diagram, we look at this picture, it may be better to understand the meaning of the U-chart.
2, Dispatchtouchevent, Ontouchevent, onintercepttouchevent
The default implementation of these methods of ViewGroup and view is to let the entire event install U-shape complete, so return super.xxxxxx () will let the event follow the direction of the U-shape complete the entire event flow path), do not make any changes in the middle, do not backtrack, do not terminate, Every step of the way.
3, Dispatchtouchevent and Ontouchevent once return true, the event stops passing (to the end) (no one can receive the event again). Fancy as long as the return true event will not continue to pass, for return true we often say that the event is consumed, consumption means that the event came here is the end, will not go down, no one can receive this event again.
4, Dispatchtouchevent, and Ontouchevent return False when the event is passed back to the parent control's ontouchevent processing.
5, the role of onintercepttouchevent
Intercept the meaning of the interception, each viewgroup each time in the distribution, ask the Interceptor to intercept (that is, ask yourself if this event should not be handled by themselves) if you want to handle it, return in the Onintercepttouchevent method. True will be given to their own ontouchevent processing, if not intercept is to continue to the child control down. The default is not to intercept, because the child view also needs this event, so the Onintercepttouchevent interceptor return Super.onintercepttouchevent () and return false is the same, is not intercepted, The event will continue to pass to the dispatchtouchevent of the child view.
6, ViewGroup and view of the Dispatchtouchevent method return Super.dispatchtouchevent () when the event flow trend.
First look at the viewgroup of the Dispatchtouchevent, said before the return true is the end of delivery. Return false is the ontouchevent that goes back to the parent view, and then viewgroup how the Dispatchtouchevent method can distribute the event to its own ontouchevent processing, return True and false are not, then only through the interceptor to intercept the event to their own ontouchevent, so ViewGroup The super default implementation of the Dispatchtouchevent method is to call onintercepttouchevent and remember this.
So what happens to the Dispatchtouchevent return Super.dispatchtouchevent () of the view, and unfortunately the view has no interceptors. But the same truth is that return true is the end. Return false is the ontouchevent of the parent class of backtracking, how to distribute the event to its own ontouchevent processing, that can only return super.dispatchtouchevent, The default implementation of the Dispatchtouchevent () method of the view class is to help you invoke view's own Ontouchevent method.
About Action_move and action_up
The above is for the Action_down event delivery, Action_move and action_up in the process of transmission is not the same as Action_down, you do action_down when the return of false, A series of other actions will no longer be executed. Simply put, it is when Dispatchtouchevent is doing event distribution that only the previous event (such as Action_down) returns true to receive Action_move and ACTION_UP events.
You'll know the rules for a few pictures.
The Red Arrows represent the direction of the Action_down event.
The blue arrows represent the direction of the Action_move and ACTION_UP events.
Drawing a lot of pictures at once, there are several cases will no longer draw, I believe you also see the law, for the situation in Ontouchevent consumption event: in which view ontouchevent return True, then Action_move and Action_ The up event is no longer passed down from the top down to the view, and it passes directly to its ontouchevent and ends the event delivery process.
For Action_move, action_up Summary: Action_down event in which control consumption (return True), then Action_move and Action_ Up will be sent from the top down (through the dispatchtouchevent) to do the event distribution down, will only upload to this control, will not continue to preach, if the Action_down event is dispatchtouchevent consumption, then the event stops delivery, If the Action_down event is consumed in Ontouchevent, the Action_move or Action_up event is passed to the control's ontouchevent processing and the pass is ended.
Overview of the Android-event distribution mechanism framework