Android Touch event distribution mechanism

Source: Internet
Author: User

During app development, custom controls are often required to handle Touch events. This article describes how the Android Application Layer distributes Touch events.

In general, the distribution of Touch events follows the "V" structure, as shown in (the figure is a bit rough:-D ): <Strong? Http: www.bkjia.com kf ware vc "target =" _ blank "class =" keylink "> VcD4KPHA + pgltzybzcm9 "http://www.bkjia.com/uploadfile/Collfiles/20140116/20140116134632289.jpg" alt = "\">


The relationship between View and ViewGroup is as follows:


There are three main points:

1. The outer ViewGroup receives the event first. ViewGroup calls intercept in dispatch to determine the distribution direction. If intercept returns true, it distributes the event to the inner control. Otherwise, it distributes the event directly to its own touch function.

2. the return value of the touch function determines whether the event will continue to be transmitted. If true is returned, the event will be consumed and will not be passed back. Otherwise, the event will be passed back.

3. The final return value of an event determines whether the subsequent event is received. If the Activity and the touch function of all controls do not consume the event (true is returned by touch), the subsequent event is no longer received; otherwise, the system continues to receive subsequent events.


The left side of the "V" font is the dispatch function. The inflection point below is the touch function of the inner View, and the touch function of the outer View on the right. Of course, the innermost layer is a ViewGroup.


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.