Reference:
https://stackoverflow.com/questions/7814017/is-it-possible-to-disable-scrolling-on-a-viewpagerCode snippet:
1. Create a new CustomViewPager classpublic class CustomViewPager extends ViewPager {
private boolean isPagingEnabled = true;
public CustomViewPager(Context context) {
super(context);
}
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return this.isPagingEnabled && super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return this.isPagingEnabled && super.onInterceptTouchEvent(event);
}
public void setPagingEnabled(boolean b) {
this.isPagingEnabled = b;
}
}
2. Replace the <com.android.support.V4.ViewPager> tag with <your_package_name.CustomViewPager > tag in layout.xml
3. Call setPagingEnabled(true) when you want to disable Scrolling and call setPagingEnabled(false) to enable it.
沒有留言:
張貼留言