public class CustomViewPager extends ViewPager {
private boolean enabled;
public CustomViewPager(Context context) {
super(context);
this.enabled = true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onTouchEvent(event);
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onInterceptTouchEvent(event);
}
return false;
}
public void setPagingEnabled(boolean enabled) {
this.enabled = enabled;
}
}
viewPager.setOnPageChangeListener(new OnPageChangeListener(){
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
if(getScale() > 0.69){
viewPager.setPagingEnabled(false);
}else{
viewPager.setPagingEnabled(true);
}
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
});
答案 0 :(得分:0)
这可能会有所帮助。我没有测试过。所以不能真的说它是否会起作用。 如果有效,请告诉我。
public class CustomViewPager extends ViewPager {
private boolean enabled;
public CustomViewPager(Context context) {
super(context);
this.enabled = true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onTouchEvent(event);
}
return super.onTouchEvent(null);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onInterceptTouchEvent(event);
}
return super.onInterceptTouchEvent(null);
}
public void setPagingEnabled(boolean enabled) {
this.enabled = enabled;
}}