Android Viewpager拦截 左右滑动

文章地址 : http://blog.csdn.net/arieshao/article/details/51395140

原理:

    通过重写 
    onInterceptTouchEvent(MotionEvent event)
            return false 
    和
    onToucheEvent (MotionEvent event)
            return falses 
    拦截,消耗处理事件的方式禁止滑动.

设置ViewPager预加载界面个数

ViewPager.setOffScreenPageLimit(pageCount);

禁止切换动画

ViewPager.setCurrentItem(pos,false);

重写ViewPager

public class UnScrollViewPager extends ViewPager {

    private boolean isScrollable = false;

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


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

    public void setScrollable(boolean scrollable) {
        isScrollable = scrollable;
    }

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

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

}

你可能感兴趣的:(Android,开发笔记)