上代码
public class NoScrollViewPager extends ViewPager {
// 是否禁止 viewpager 左右滑动
private boolean noScroll = true;
public NoScrollViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent arg0) {
if (noScroll){
return false;
}else{
return super.onTouchEvent(arg0);
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
if (noScroll){
return false;
}else{
return super.onInterceptTouchEvent(arg0);
}
}
}
直接在xml中引用就行