Android Requestdisallowintercepttouchevent use

Source: Internet
Author: User

Viewpager to achieve left and right swipe to toggle tab. Assuming that a horizontal sliding view is embedded in one of the tab items, you might be uncomfortable, such as sliding a horizontally sliding control in the TAB key, causing the tab to switch.

Since the Android event mechanism is transmitted from the parent view to the child view, it is possible to detect if your current sub-view has a sliding control, etc., to determine if the event is blocked. But this trouble, and does not solve all the problems (it is necessary to check whether the touch point is on this control), in fact there is a simpler way to inject a Viewpager instance into your nested control (call the control's GetParent () method), and then in Ontouchevent. Onintercepttouchevent. Dispatchtouchevent inside to tell the parent view. That is, Viewpager do not intercept touch events on the control.

1 requestdisallowintercepttouchevent (true)

The code is generally such as the following:

1  Public BooleanOnTouch (View V, motionevent event) {2     Switch(Event.getaction ()) {3      CaseMotionevent.action_move:4Pager.requestdisallowintercepttouchevent (true);5          Break;6      Casemotionevent.action_up:7      CaseMotionevent.action_cancel:8Pager.requestdisallowintercepttouchevent (false);9          Break;Ten     } One}

When the user presses, we tell the parent component. Do not intercept my events (this is when a subassembly can respond normally to an event for a time) and pick up will tell the parent ingredient can be prevented.

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Android Requestdisallowintercepttouchevent use

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.