Viewpager undo left and right swipe toggle function

Source: Internet
Author: User

Viewpager Cancel left and right swipe toggle function

Recent projects require that in some cases viewpager cannot slide, then we just need to override this method to disable Viewpager sliding

Indexviewpager.java:

Import Android.content.context;import Android.support.v4.view.viewpager;import Android.util.attributeset;import Android.view.motionevent;public class Indexviewpager extends Viewpager {private Boolean iscanscroll = False;public Indexviewpager (Context context) {super (context);} Public Indexviewpager (context context, AttributeSet Attrs) {Super (context, attrs);} public void Setscanscroll (Boolean iscanscroll) {this.iscanscroll = Iscanscroll;} @Overridepublic void ScrollTo (int x, int y) {super.scrollto (x, y);} @Overridepublic boolean ontouchevent (motionevent arg0) {//TODO auto-generated method stubif (iscanscroll) {return super. Ontouchevent (arg0);} else {return false;}} @Overridepublic void Setcurrentitem (int item, Boolean smoothscroll) {//TODO auto-generated method Stubsuper.setcurrentitem (item, smoothscroll);} @Overridepublic void Setcurrentitem (int item) {//TODO auto-generated method Stubsuper.setcurrentitem (item);} @Overridepublic boolean onintercepttouchevent (motionevent arg0) {//TODO Auto-generated method Stubif (iscanscroll) {return super.onintercepttouchevent (arg0);} else {return false;}}} 

<yourpackeagename.indexviewpager        android:id= "@+id/vpager"        android:layout_width= "Wrap_content        " android:layout_height= "Wrap_content"        android:layout_gravity= "center"        android:layout_weight= "1.0"        Android:background= "#000000"        android:flipinterval= "android:persistentdrawingcache="        animation "/>

Viewpager undo left and right swipe toggle function

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.