First, in view, there are two callback functions (leaf view, can not add control view, such as: Textview,imageview)
public boolean dispatchtouchevent (Motionevent ev);
public boolean ontouchevent (Motionevent ev);
Second, in ViewGroup, there are three callback functions (Layout,adapterview)
public boolean dispatchtouchevent (Motionevent ev);
public boolean onintercepttouchevent (Motionevent ev);
public boolean ontouchevent (Motionevent ev);
Three, in activity, there are two callback functions
public boolean dispatchtouchevent (Motionevent ev);
public boolean ontouchevent (Motionevent ev);
When touchevent occurs, the activity first passes the touchevent to the topmost viewgroup, TouchEvent first to the topmost viewgroup, and then by the Dispatchtouchevent method for distribution.
(generally not overriding dispatchtouchevent, overriding dispatchtouchevent must call super.dispatchtouchevent (EV); otherwise intercepttouchevent will not be called and Ontouchevent, the event is over. )
Returning false indicates that no subsequent events are accepted, so this subsequent operation does not work.
If true, the ViewGroup Intercepttouchevent method is given to determine whether to intercept the event,
If Intercepttouchevent returns True, that is, it is intercepted, it is given to the ontouchevent of the viewgroup intercepting it to handle,
If Intercepttouchevent returns false, it is passed to the child view. The dispatchtouchevent of the child view begins the distribution of this event. If the child view is ViewGroup, repeat the above action.
If the child view is a leaf view,dispatchtouchevent returns true, it means that it needs to handle the event, and the event will be passed to Ontouchevent.
Ontouchevent returns FALSE, the event is passed to the ontouchevent () processing of the view on its previous level. (When you return false, pass it to the parent view);
Ontouchevent () returns True, then subsequent events will continue to be passed to the view's ontouchevent () processing.
Otherwise, if the dispatchtouchevent of the leaf view returns false, it does not have to be processed, and it is not allowed to receive subsequent touch-screen events. Pass the subsequent events up to the parent view's ontouchevent processing
The ontouchevent default value in ViewGroup is false.
The ontouchevent in view returns the default value of True.
The transfer mechanism of the touch event between Onintercepttouchevent () and ontouchevent and each childview depends entirely on the return value of Onintercepttouchevent () and Ontouchevent ().
A return value of TRUE indicates that the event was received and processed correctly, and the return value of FALSE indicates that the event was not processed and will continue to be passed
(Just transfer direction is different, onintercepttouchevent () to the child view, and Ontouchevent () to the parent view).
Handling of Android Touch events