Events such as Onclick,onlongclick,onfling,onscroll in Android are made up of multiple Ontouch events, and a complete touchscreen event must contain 1 Action_down (pressed), multiple action_ Move, 1 action_up (release), touch event distribution is the process by which these events rotate between viewgroup and view.
1, ViewGroup inheritance View,view contains Dispatchtouchevent and ontouchevent two and event distribution directly related to two methods, ViewGroup also defines a onintercepttouchevent method in addition to rewriting the view's Dispatchtouchevent method;
Dispatchtouchevent:touch the initiator of the event distribution, each touch event must first call the method
Onintercepttouchevent: Exists only in the ViewGroup container, which determines whether the current event can be passed to the Groupview child control view
Ontouchevent: Receive and Process event, return value True indicates consumption of current event
2, for a viewgroup touch event, the first trigger is the dispatchtouchevent, The Dispatchtouchevent method invokes the Onintercepttouchevent method to determine whether an event is a ontouchevent event that is passed to ViewGroup ontouchevent or a child view
Look at the following onintercepttouchevent calling code
Final Booleanintercepted; if(actionmasked = =Motionevent.action_down|| Mfirsttouchtarget! =NULL) { Final BooleanDisallowintercept = (Mgroupflags & flag_disallow_intercept)! = 0; if(!disallowintercept) {Intercepted=onintercepttouchevent (EV); Ev.setaction (action); //Restore action in case it was changed}Else{intercepted=false; } } Else { //There is no touch targets and this action is not a initial down//So the view group continues to intercept touches.intercepted =true; }
intercepted ==true is to indicate that the parent container will intercept the touchscreen event and that subsequent events will not be passed to the child view;Mfirsttouchtarget means the child view,flag_disallow_ that consumed the Touch_down event Intercept indicates whether the child view setting allows the event to be truncated by the parent container
Android Ontouch event distribution mechanism