Overall understanding of Android touch event processing, android touch
First look at several functions:When talking about Android touch event processing, many people will immediately think of some troublesome functions. Here we will list them to stimulate your little nerves:
@Override public boolean onTouchEvent(MotionEvent event) { return super.onTouchEvent(event); } @Override public boolean dispatchTouchEvent(MotionEvent ev) { return super.dispatchTouchEvent(ev); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { return super.onInterceptTouchEvent(ev); } @Override public boolean onTouch(View v, MotionEvent event) { return false; }
Well, today, let's take a look at the functions of these four functions and their call relationships to clarify the touch event processing mechanism.
I. Let's take two of them first:
@Override public boolean onTouchEvent(MotionEvent event) { return super.onTouchEvent(event); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { return super.onInterceptTouchEvent(ev); }
1.1 first, it is clear that Android event distribution and processing areTop-downThe first time a touch event is sent to the View on the outermost layer.
1.2 here is an example: we assume that multiple viewgroups in a window form a big family, with the maximum number of views on the outermost layer and the minimum number of views on the innermost layer, then, compare a touch event to an apple event. If an event (an apple is obtained) occurs, the following will happen:
Apple's transfer process:
Grandpa --> dad --> Sun Tzu.
If Grandpa eats the apple, we say the event was consumed.
See:
Further detailed analysis:
So far, is there a general grasp of the message transmission mechanism in Android,
Next, let's clarify some details.