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