去除ViewPager界面切换动画、禁止滑动

public class CustomViewPager extends ViewPager {


	public CustomViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public CustomViewPager(Context context) {
		super(context);
	}
	
	//去除页面切换时的滑动翻页效果
		@Override
		public void setCurrentItem(int item, boolean smoothScroll) {
			// TODO Auto-generated method stub
			super.setCurrentItem(item, smoothScroll);
		}

		@Override
		public void setCurrentItem(int item) {
			// TODO Auto-generated method stub
			super.setCurrentItem(item, false);
		}

}

直接继承即可


加入以下代码可以禁止滑动,也可单独使用

private static final String TAG = "MyViewPager";
	private boolean result = false;

	public CustomViewPager(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public CustomViewPager(Context context) {
		super(context);
	}

	@Override
	public boolean onInterceptTouchEvent(MotionEvent arg0) {
		if (result)
			return super.onInterceptTouchEvent(arg0);
		else
			return false;
	}

	@Override
	public boolean onTouchEvent(MotionEvent arg0) {
		if (result)
			return super.onTouchEvent(arg0);
		else
			return false;
	}


/**
     * 解决viewPager与百度地图滑动冲突
     * */
    @Override
    protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
        if(v.getClass().getName().equals("com.baidu.mapapi.map.MapView")) {
            return true;
        }
        //if(v instanceof MapView){
        //    return true;
        //}
        return super.canScroll(v, checkV, dx, x, y);
    }


你可能感兴趣的:(组件,云宽项目)