Skip to content

Instantly share code, notes, and snippets.

@Lanace
Created January 19, 2017 02:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lanace/6c41c752390cca24ce088931d02676a0 to your computer and use it in GitHub Desktop.
Save Lanace/6c41c752390cca24ce088931d02676a0 to your computer and use it in GitHub Desktop.
Disable horizontal scroll in ViewPager
public class CustomViewPager extends ViewPager {
private boolean isPageScrollEnabled = true;
public CustomViewPager(Context context) {
super(context);
}
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return this.isPageScrollEnabled && super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return this.isPageScrollEnabled && super.onInterceptTouchEvent(event);
}
public void setPageScrollEnabled(boolean isPageScrollEnabled) {
this.isPageScrollEnabled = isPageScrollEnabled;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment