Created
January 19, 2017 02:12
-
-
Save Lanace/6c41c752390cca24ce088931d02676a0 to your computer and use it in GitHub Desktop.
Disable horizontal scroll in ViewPager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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