Use of Android Requestdisallowintercepttouchevent

Source: Internet
Author: User

Viewpager to move the tab to the left and right, if a horizontal sliding view is embedded in an item in the tab, it can make you feel uncomfortable, such as sliding a horizontally sliding control in the TAB key, which results in tab switching.

Because the Android event mechanism is passed from the parent view to the child view, it is possible to detect whether your current sub-view has a sliding control, and so on, which determines if the event is blocked, but this is a hassle and does not solve all the problems (you must detect if the touch point is on this control), There is actually a simpler way to inject a Viewpager instance into your nested control (call the control's GetParent () method), and then in Ontouchevent,onintercepttouchevent, Dispatchtouchevent tells the parent view that Viewpager does not intercept touch events on the control.

1 requestdisallowintercepttouchevent (true)

The code is generally as follows:

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 not to intercept my events (at this point the subassembly is able to respond to the event normally) and then pick up and tell the parent that the component can block.

Use of Android Requestdisallowintercepttouchevent

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.