One of the event passes (basic concept)

Source: Internet
Author: User

One of the Android event delivery mechanisms

Event delivery refers to the process of how a down, move,up event will be passed when multiple view overlays are in the same area in Android application development, and if the view is in the same region.

Suppose a viewgroup contains a view, and what methods ViewGroup and view trigger when the user presses the view.

Before we learn about these events, let's look at the concepts of several methods:

1. Dispatchtouchevent: This method only inherits the ViewGroup class, is the function that points to the Childview distribution event, that is, when the hand presses the position of view (or ViewGroup), All Childview events are distributed through dispatchtouchevent through the ViewGroup dispatchtouchevent event, which is the trigger before all view events are acquired.

2. Onintercepttouchevent: This method only inherits the ViewGroup class only, after Dipatchtouchevent distributes, will be captured by Onintercepttouchevent, this method acts as an interception event,

If this method is return true, the subsequent events are no longer processed. For example, when Oninterecpttouchevent is down and returns True, the event will not continue to be passed to the ontouchevent of the child view.

Instead, the event is passed to the current ViewGroup ontouchevent for processing

3.onTouchEvent: This method is available for both viewgroup and view because both ViewGroup and view are subclasses of view, so ontouchevent is a function of view.


Here is a concrete example to describe the event delivery process

Suppose a linearlayout contains a textview, when the user clicks on TextView, how the event will be passed (for convenience of description, respectively, using L1,T1)

1. If the event is passed by default in the following order

L1 dispatchtouchevent down and L1 oninterecpttouchevent down->t1 ontouchevent, by default this is the order of delivery

    1. If T1 's Ontouchevent's down return is false , then the event disappears and no longer continues to pass.
    2. If T1 's ontouchevent is down to true , then the event will be passed to L1 ontouchevent, so the event has the following process
    3. L1 's dispatchtouchevent down, L1 's oninterecpttouchevent down->t1 Ontouchevent's->l1 down ontouchevent

2. So we can draw a conclusion

    1. If the ontouchevent of the child view returns True, the down event will no longer continue to pass down, and if the child view's Ontouchevent returns false, the down continues to be passed to Childview The ontouchevent of the parent
    2. The up event does not go down the ontouchevent pass of the event, who handles the ontouchevent down event and returns True (then the event no longer continues to pass), and who processes the up event, So if the down event is passed to the top-level Parentview, and the ontouchevent of the top-level parent view returns FALSE, the program loses the UP event.



One of the event passes (basic concept)

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.