/**
* 支持禁用左右滑动切换的ViewPager
* setScrollable true 支持滑动切换 false 不允许滑动切换
* Created by Peekaboo on 2021/5/28 19:56
*/
public class DisableScrollViewPager extends ViewPager {
private boolean mIsEnableScroll = true;
public DisableScrollViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DisableScrollViewPager(Context context) {
super(context);
}
public void setIsEnableScroll(boolean isEnableScroll) {
this.mIsEnableScroll = isEnableScroll;
}
@Override
public void scrollTo(int x, int y) {
super.scrollTo(x, y);
}
@Override
public boolean onTouchEvent(MotionEvent arg0) {
if (!mIsEnableScroll)
return false;
else
return super.onTouchEvent(arg0);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
if (!mIsEnableScroll)
return false;
else
return super.onInterceptTouchEvent(arg0);
}
@Override
public void setCurrentItem(int item, boolean smoothScroll) {
super.setCurrentItem(item, smoothScroll);
}
@Override
public void setCurrentItem(int item) {
super.setCurrentItem(item);
}
}
支持禁用左右滑动切换的ViewPager
最新推荐文章于 2022-07-13 16:25:24 发布