关闭Fragment+Viewpager的页面滑动

自定义MyViewPager 继承Viewpager

 public class MyViewPager extends ViewPager {
private boolean isCanScroll = false;

public MyViewPager(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
}

public MyViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
}
public void setScanScroll(boolean isCanScroll) {
    this.isCanScroll = isCanScroll;
}

@Override
public void scrollTo(int x, int y) {
    super.scrollTo(x, y);
}

@Override
public boolean onTouchEvent(MotionEvent arg0) {
    // TODO Auto-generated method stub
    if (isCanScroll) {
        return super.onTouchEvent(arg0);
    } else {
        return false;
    }

}

@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);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
    // TODO Auto-generated method stub
    if (isCanScroll) {
        return super.onInterceptTouchEvent(arg0);
    } else {
        return false;
    }

}
}

改变布局

 <com.bawei.jingdong.bao.MyViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/radioGroup"
    />

猜你喜欢

转载自blog.csdn.net/jiaosheng1/article/details/79033468
今日推荐