Distribution and transmission mechanism of Android events in the image talking Series

Source: Internet
Author: User

Distribution and transmission mechanism of Android events in the image talking Series

In some complex la S, we often encounter problems such as event conflicts and event invalidation. This requires us to have a deep understanding of the distribution and transfer mechanism of Android events. The best way is to write a demo by yourself, print the Event-related logs to view the running process, and then deeply understand it with the source code. Of course, this will not be done here. There are only summative things here. If you like this kind of things, please continue to look at it.

Old rules: first:

 

User interaction usually occurs on the touch screen. Therefore, the transmission of Android events must involve ViewGroup and View. The methods for passing event processing in ViewGroup and View are as follows:

ViewGroup:

public boolean dispatchTouchEvent(MotionEvent event)public boolean onTouchEvent(MotionEvent event) public boolean onInterceptTouchEvent(MotionEvent event)

View:

public boolean dispatchTouchEvent(MotionEvent event)public boolean onTouchEvent(MotionEvent event) 

 

DispatchTouchEvent is responsible for event distribution, onTouchEvent is responsible for event processing, and onInterceptTouchEvent is responsible for event interception. You can see that only ViewGroup has the onInterceptTouchEvent method.

 

After learning about the basic event-related methods, let's look at some key points:

1. Upload sequence of Android events: Activity ---> ViewGroup ---> View.

2. If true is returned in dispatchTouchEvent, the distribution will not continue, and the event will be canceled. If false is returned, the event will continue to be passed.

3. If the onInterceptTouchEvent of ViewGroup returns true, the event is intercepted, so the event is not passed down to the View and handed over to the ViewGroup itself for processing. If false is returned, the event is still transmitted to the View.

4. If onTouchEvent returns true, it indicates that it consumes the event, but does not respond to onClickListener. If it returns false, it will continue to respond to onClickListener, if it has been set.

5. For more information, see the description in.



Related Article

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.