If super. onTouchEvent (ev) is returned, the default event processing logic is the same as when false is returned.From this table, we can see that ViewGroup and View can respond to all three methods related to Touch events, while Activity does not respond to onInterceptTouchEvent (MotionEvent ev), that is, event interception. In addition, you must note that the View responds to dispatchTouchEvent (MotionEvent ev) and onInterceptTouchEvent (MotionEvent ev) only if you can add a subview to the View, if the current View is already a smallest unit View (such as TextView), you cannot add a subview to the smallest View, and you cannot distribute or intercept events to the subview, therefore, it does not have dispatchTouchEvent (MotionEvent ev) and onInterceptTouchEvent (MotionEvent ev), and only onTouchEvent (MotionEvent ev ).
I. Touch Event Analysis
? Event distribution: public boolean dispatchTouchEvent (MotionEvent ev)
DispatchTouchEvent (MotionEvent ev) of the Activity when the Touch event occurs) the method will be in the tunnel mode (pass down from the root element until the inmost layer sub-element or stop passing because of a certain condition in the middle of a mona1 element) the event is passed to the dispatchTouchEvent (MotionEvent ev) method of the outermost View, and the dispatchTouchEvent (MotionEvent ev) method of the View distributes the event. The event distribution logic of dispatchTouchEvent is as follows:
? Event interception: public boolean onInterceptTouchEvent (MotionEvent ev)
When the dispatchTouchEvent (MotionEvent ev) method of the outer View returns the system's default super. dispatchTouchEvent (ev), the event is automatically distributed to the onInterceptTouchEvent method of the current View. The event interception logic of onInterceptTouchEvent is as follows:
? Event Response: public boolean onTouchEvent (MotionEvent ev)
When dispatchTouchEvent returns super. dispatchTouchEvent (ev) and onInterceptTouchEvent returns true or super. onInterceptTouchEvent (ev), onTouchEvent is called. The Event Response logic of onTouchEvent is as follows:
The following figure shows the entire event Transfer Process (layout: viewGroup1 is in the outermost layer, with a nested viewGroup2 and a Button added to viewGroup2 ). It can also be seen that the event is first transmitted to the corresponding layout (viewGroup1) of the outermost layer, and then to the inner layer (viewGroup2) in turn. When it is passed to the inner layer of View (Button ), if the View is already a minimum unit, it will be handed over to the onTouchEvent of the View to process the event. If the event is not consumed, the event will be returned up until no one processes the event, events will be lost.