手动控制viewpager是否可以左右滑动,去除滑动动画

铁石心肠 1年前 ⋅ 731 阅读
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); */
switch(arg0.getAction()){
}


return !noScroll && super.onTouchEvent(arg0);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
return !noScroll && super.onInterceptTouchEvent(arg0);
}

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

@Override
public void setCurrentItem(int item) {
//false 去除滚动效果
super.setCurrentItem(item,false);
}

}

全部评论: 0

    我有话说:

    咨询问题

    点击这里给我发消息

    淘宝咨询

    博主承接代做业务

    真·送云服务器

    咨询博主