Sliding event conflict handling for Android Viewpager and Slidingpanelayout (reprint)

Source: Internet
Author: User
Tags gety

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)

Related Article

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.