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