美文网首页
ViewPager禁止滑动和禁止切换动画

ViewPager禁止滑动和禁止切换动画

作者: Y小圆脸 | 来源:发表于2017-06-15 21:53 被阅读708次

    public class NoScrollViewPager extends ViewPager {
    private boolean noScroll = false;

        public NoScrollViewPager(Context context, AttributeSet attrs) {
            super(context, attrs);
            // TODO Auto-generated constructor stub
        }
    
        public NoScrollViewPager(Context context) {
            super(context);
        }
    
        public void setNoScroll(boolean noScroll) {
            this.noScroll = noScroll;
        }
    
        @Override
        public void scrollTo(int x, int y) {
            super.scrollTo(x, y);
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent arg0) {
            /* return false;//super.onTouchEvent(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);
        }
    
        @Override
        public void setCurrentItem(int item, boolean smoothScroll) {
            super.setCurrentItem(item, smoothScroll);
        }
    
        @Override
        public void setCurrentItem(int item) {
            super.setCurrentItem(item);
        }
    
    }

    相关文章

      网友评论

          本文标题:ViewPager禁止滑动和禁止切换动画

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