Overall grasp of touch event handling in Android

Source: Internet
Author: User

first look at a few functions: mention of the Android Touch event processing, many people will immediately think of some of the headaches of the function, here to list, 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, let's take a look at the function of these four functions and the call relationship between them to clarify the touch event handling mechanism.

First, let's take care of two of them:

    @Override    publicbooleanonTouchEvent(MotionEvent event) {        returnsuper.onTouchEvent(event);    }    @Override    publicbooleanonInterceptTouchEvent(MotionEvent ev) {        returnsuper.onInterceptTouchEvent(ev);    }

1.1 First make it clear that the Android event distribution and processing is top-down , i.e. a touch event must be sent to the outermost view for the first time.
1.2 Here we give an example: we assume that multiple viewgroup of a window make up a large family, with the outermost view generational the longest, the innermost view generational the smallest, and a touch event is likened to an apple. So, if an event happens (get an apple), the following things will happen:

Apple's transfer process:

Grandpa---papa--grandson.

What if the grandfather ate the apples, then we called the event consumed.

See:

To analyze in detail:

At this point, is not the message delivery mechanism in Android has a whole grasp of it,
Let's find out some details.

Overall grasp of touch event handling in Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.