Android ViewPager 禁止滑动

2019-11-23  本文已影响0人  凉风望月

public class NoScrollViewPagerextends ViewPager {

private boolean noScroll =true;

        public NoScrollViewPager(Context context) {

                super(context);

    }

public NoScrollViewPager(Context context, AttributeSet attrs) {

            super(context, attrs);

    }

public void setScrollAble(boolean canScroll) {

            this.noScroll = canScroll;

    }

@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);

    }

}

上一篇下一篇

猜你喜欢

热点阅读