美文网首页
Android ViewPager 禁止滑动

Android ViewPager 禁止滑动

作者: 凉风望月 | 来源:发表于2019-11-23 16:37 被阅读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);

        }

    }

    相关文章

      网友评论

          本文标题:Android ViewPager 禁止滑动

          本文链接:https://www.haomeiwen.com/subject/lkvhwctx.html