ViewGroup&View&Activity onInterceptTouchEvent&dispatchTouchEvent&onTouch整理

I have always had a little knowledge of this piece of knowledge, so I found some time today to take a good look at it.

First, as we all know, the three overridden methods
(
onInterceptTouchEvent&dispatchTouchEvent&onTouch
)

will have a return value. Boolean, we can understand that

true means that the event event has been consumed and will not be passed later.

false means that the event is not consumed and continues to pass backwards.

If the events of each layer are not consumed, the delivery order is roughly like this



viewgroup dispatchTouchEvent --> viewgroup onInterceptTouchEvent --> textview onTouch --> viewgroup onTouch

I only use two layers here, one viewgroup, one ordinary textview,
(if The same is true for many levels,
   onInterceptTouchEvent is intercepted layer by layer from the bottom viewgroup, and
   ontouch is passed down layer by layer from the top subview)


If an event in the viewgroup is consumed in onInterceptTouchEvent,
the subsequent events will not be passed to the onInterceptTouchEvent out.
It will not go to the ontouch of the child view. It will only go to the ontouch method of the viewgroup layer.
As shown in the figure



, if onInterceptTouchEvent is not intercepted when ACTION_DOWN, it is intercepted when ACTION_UP
and consumes events when ACTION_DOWN, and subsequent events according to the process should be passed to the sub view here
, but because
The ACTION_UP event is intercepted by the viewgroup, so the child view will go to ACTION_CANCEL by default. Of course, because the child view consumes the event when ACTION_DOWN, the ontouch of the viewgroup will not go.
The log is as follows:


In addition, I encountered a problem when writing the article.
Both the onInterceptTouchEvent of the viewgroup and the onTouch of the child view return false,
then only ACTION_DOWN will go, but ACTION_UP will not go, it should go.
Because the normal click or displacement events are ACTION_DOWN, ACTION_UP, ACTION_MOVE, since they are not intercepted, then the subsequent events should be finished?
Some people on the Internet answered that



it was vague, but it did work. I don’t know which great god can explain it to the younger brother in a simple way~


Refer to http://my.oschina.net/fengheju/blog/196608?_t=t
http://bbs.csdn.net/topics/380019043


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326604893&siteId=291194637