Android swipe conflict and how to resolve

Source: Internet
Author: User

The first thing to understand is the event distribution mechanism.

With regard to the event distribution mechanism, ViewGroup's event distribution has 3 key methods Dispathertouchevent,onintercepttouchevent,ontouchevent.

Distribute, intercept, execute.

The emergence of sliding collisions, mainly because of the existence of multiple layers of nested sliding viewgroup, then if really to this scene, how should the response? Which layer of sliding events should I respond to?

Multi-layer nested sliding viewgroup, three cases (two layers nested inside and outside the sliding direction of the same, two layers nested inside and outside the sliding direction is inconsistent, inside and outside nested more than 3 layers with 3 layers), it is supposed to say, if do not do any processing, the program should default response to all the sliding events, but in fact, This default approach is often not the result we want.

So, how to solve the sliding conflict?

Method 1)oninterceptortouchevent external interception , the person who knows the message distribution mechanism should be familiar with this method, which is used to intercept the touch events sent from outside to inside, if the return value is true, Will not be sent down the message. Ensure that only the outer layer responds to sliding events, thereby resolving the conflict.

Method 2)dispathtouchevent internal interception ,

The actual case, which was later filled.

Android swipe conflict and how to resolve

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.