Recently in a project need to use the Viewpager load ad map, layout needs to slide, using the Android V4 Package Slidingpanelayout control (the control in the old V4 package does not have, need to update V4 package), when used in the project, found that the Viewpager and slidingpanelayout sliding in the slide conflict, when the finger swipe from left to right, Viewpager's sliding events are slidingpanelayout masked, can only perform slidingpanelayout events , while sliding from right to left is normal.
Domestic find some information, found not particularly good, finally still rely on VPNFQ to foreign forum to find (sure is the world's largest LAN), this issue in the foreign forum suddenly found (have to say that foreign resources is rich, to foreign friends point a praise) so the following processing code, is reproduced abroad, Can be directly copied to use, temporarily did not find the problem, there are problems later modified.
Here is the process step, create a new class yourself, inherit from Slidingpanelayout, and then add the class to the XML file you want to lay out, so you can. Paste the code below.
PackageCom.zuzuChe.view;ImportAndroid.content.Context;ImportAndroid.support.v4.view.MotionEventCompat;Importandroid.support.v4.widget.SlidingPaneLayout;ImportAndroid.util.AttributeSet;Importandroid.view.MotionEvent;Importandroid.view.ViewConfiguration;/*** Created by Apaojun on 2015/2/12.*/ Public classPagerenabledslidingpanelayoutextendsSlidingpanelayout {Private floatMinitialmotionx; Private floatMinitialmotiony; Private floatMedgeslop; PublicPagerenabledslidingpanelayout (Context context) { This(Context,NULL); } PublicPagerenabledslidingpanelayout (Context context, AttributeSet attrs) { This(context, Attrs, 0); } PublicPagerenabledslidingpanelayout (context context, AttributeSet attrs,intDefstyle) { Super(context, attrs, Defstyle); Viewconfiguration Config=Viewconfiguration.get (context); Medgeslop=Config.getscalededgeslop (); } @Override Public Booleanonintercepttouchevent (motionevent ev) {Switch(motioneventcompat.getactionmasked (EV)) { Casemotionevent.action_down: {Minitialmotionx=Ev.getx (); Minitialmotiony=ev.gety (); Break; } CaseMotionevent.action_move: {Final floatx =Ev.getx (); Final floaty =ev.gety (); //The user should always is able to "close" the pane and so we only check//For child scrollability if the pane is currently closed. if(Minitialmotionx > Medgeslop &&!isopen () && CanScroll ( This,false, Math.Round (x-Minitialmotionx), Math.Round (x), Math.Round (y))) {//How do we set Super.misunabletodrag = true? //Send the parent a cancel eventMotionevent CancelEvent =motionevent.obtain (EV); Cancelevent.setaction (Motionevent.action_cancel); return Super. Onintercepttouchevent (CancelEvent); } } } return Super. onintercepttouchevent (EV); }}
Sliding event conflict handling for Android Viewpager and Slidingpanelayout (reprint)