自定义ViewPager禁止滑动,滑动效果不显示

自定义view:

public class CustomViewPager extends ViewPager {

private boolean isCanScroll = true;

private boolean noScroll = false;

public CustomViewPager(@NonNull Context context) {
    super(context);
}

public CustomViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
}

public void setCanScroll(boolean canScroll) {
    this.isCanScroll = canScroll;
}

public void setNoScroll(boolean noScroll) {
    this.noScroll = noScroll;
}

@Override
public void scrollTo(int x, int y) {
    super.scrollTo(x, y);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    return isCanScroll && super.onInterceptTouchEvent(ev);
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()){

    }
    return isCanScroll && super.onTouchEvent(ev);
}

@Override
public void setCurrentItem(int item, boolean smoothScroll) {
    super.setCurrentItem(item, smoothScroll);
}

@Override
public void setCurrentItem(int item) {
//false:不显示滑动效果
    super.setCurrentItem(item,false);
}
}

activity:

vp.setCanScroll(false);//禁止滑动

你可能感兴趣的:(自定义ViewPager禁止滑动,滑动效果不显示)