in some complex layouts, there are often issues such as event collisions, event failures, and so on, which requires an in-depth understanding of Android the distribution delivery mechanism for the event. The best way is to write a demoyourself, print the event-related logs to see its running process, and then combined with the source to understand deeply. Of course there is no such thing here, there is only a summary of things, if you like this kind of things, then please continue to look down.
The usual, first:
user interaction typically occurs on the touchscreen, so the transmission of the Android event will inevitably involve viewgroup and View, ViewGroup with the View the methods involved in handling event delivery are as follows:
ViewGroup:
<span style= "FONT-SIZE:14PX;" >public boolean dispatchtouchevent (Motionevent event) Public boolean ontouchevent (Motionevent event) Public boolean Onintercepttouchevent (Motionevent event) </span>
View:
<span style= "FONT-SIZE:14PX;" >public boolean dispatchtouchevent (Motionevent event) Public boolean ontouchevent (Motionevent event) </span>
where dispatchtouchevent is responsible for event distribution,ontouchevent is responsible for event handling,onintercepttouchevent responsible for event interception. As you can see, only viewgroup has the onintercepttouchevent method.
After understanding the basic methods of event correlation, take a look at some key points:
1.Android Event Delivery order:Activity--->viewgroup--->view.
2. If trueis returned in dispatchtouchevent , thedistribution is no longer continued, the event is canceled , and falseis returned. The event is passed on.
3. If viewgroup onintercepttouchevent return true The interception event is not passed down to the view viewgroup self-processing; if you return false view
4. If ontouchevent returns true, it indicates that it consumes the event but does not respond to onclicklistener; false, it will continue to respond to onclicklistenerIf it has been set.
5. The other can be referenced in the specific description.
Picture will talk series of Android events distribution delivery mechanism