重写ViewPager禁止左右滑动

??

自定义ViewPager

public class CustomViewPager extends ViewPager { /**1 默认true 可以滑动; * * 2 只需要将返回值改为false,那么ViewPager就不会消耗掉手指滑动的事件了, * 转而传递给上层View去处理或者该事件就直接终止了。*/ private boolean isCanScroll = false; public CustomViewPager(Context context) { super(context); }public CustomViewPager(Context context, AttributeSet attrs) { super(context, attrs); }public void setScanScroll(boolean isCanScroll){ this.isCanScroll = isCanScroll; }@Override public void scrollTo(int x, int y){ super.scrollTo(x, y); }@Override public void setCurrentItem(int item) { // TODO Auto-generated method stub super.setCurrentItem(item); }@Override public boolean onTouchEvent(MotionEvent arg0) { // TODO Auto-generated method stub if (isCanScroll) { return super.onTouchEvent(arg0); } else { return false; } }@Override public boolean onInterceptTouchEvent(MotionEvent arg0) { // TODO Auto-generated method stub if (isCanScroll) { return super.onInterceptTouchEvent(arg0); } else { return false; } }}

??

    推荐阅读