android-viewpager-disabling left and right slide events

Source: Internet
Author: User

Viewpager is a good interface container, but sometimes it may not be necessary to move the left and right events, and then list a way

Method:

Write a custom class, inherit Viewpager, then rewrite the Ontouchevent event and do nothing

1 ImportAndroid.content.Context;2 ImportAndroid.support.v4.view.ViewPager;3 ImportAndroid.util.AttributeSet;4 Importandroid.view.MotionEvent;5 6 /**7 * Can not be left and right sliding Viewpager8  * 9  * @authorKevinTen  * One  */ A  Public classNoscrollviewpagerextendsViewpager { -  -      PublicNoscrollviewpager (Context context, AttributeSet attrs) { the         Super(context, attrs); -     } -      -      PublicNoscrollviewpager (Context context) { +         Super(context); -     } +      A     //rewrite the Ontouchevent event and don't do anything at @Override -      Public Booleanonintercepttouchevent (motionevent ev) { -         return false; -     } -      -     /** in * Rewrite ontouchevent, don't do anything -      */ to @Override +      Public Booleanontouchevent (motionevent ev) { -         return false; the     } *  $ Panax Notoginseng}

android-viewpager-disabling left and right slide events

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.