For Android developers to understand the importance of the event delivery mechanism, I think it should be self-evident. In an activity, we often rewrite the Ontouchevent event, but after the rewrite is over, it is confusing to return TRUE or return false. When the mood is good, return true, when the mood is bad, return false.
To fully understand the event interception mechanism, we first need to understand the role of these methods: Dispatchtouchevent (motionevent ev), onintercepttouchevent (motionevent ev), Ontouchevent (motionevent ev).
First, let's throw a question, what happens when we click on a button in the LinearLayout and follow the event-passing mechanism? Will find viewgroup inside, we can rewrite the above three methods, but in a separate sub-view, we can only rewrite: dispatchtouchevent (motionevent ev), Ontouchevent (motionevent EV). Why is it? So here's what we're going to do to each of these three methods.
The dispatchtouchevent (motionevent ev) method acts as a distribution event, and when an event arrives at the current view, view calls the method to distribute the event, correctly passing it to the control that can handle the response. The parameter motionevent that the method carries has encapsulated the response parameter information of the event.
The onintercepttouchevent (motionevent ev) method action is whether to intercept the event, when an event arrives at the view, if the view overrides the method returns True, then the view is able to handle the response to the event, Then the event will not continue to pass down the surface. If the overridden method returns false, the event will continue to be passed to the child control on the lower side, eventually reaching the child view that can respond.
The ontouchevent (motionevent ev) method is where the response event is processed, and a Boolean value is returned when the method executes, except that the Boolean value is to determine if a view is needed to feedback information to the parent. Just like when you complete a task, you need to report the results to the project manager. If it returns true, then the feedback is not needed and I have handled it well. If False is returned, then it is necessary to give the parent view feedback so that it determines the final result state.
Of course, the above three method parameters are motionevent, indicating that the parameter information of the event will be carried.
The event interception mechanism of the Android Development series