要实现viewpager的滑动和制止滑动切换功能只需要继承viewpager,在onTouchEvent进行逻辑判断便可(网上搜到的,确切可行,原创地址不明),下面自己实现1个
public class MyViewPager extends ViewPager {
private boolean scrollble=true;
public MyViewPager
super(context);
}
public MyViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (!scrollble) {
return true;
}
return super.onTouchEvent(ev);
}
public boolean isScrollble() {
return scrollble;
}
public void setScrollble(boolean scrollble) {
this.scrollble = scrollble;
}
}
使用时只需要根据需要调用setScrollble(true/false)便可进行切换!!!