我的应用程序中有一个 ViewPager,我想随时禁用/允许向右滑动。viewpager 中的每个视图都包含 ListView。我怎样才能做到这一点?我正在尝试以这种方式做到这一点:
private int oldX;
private int deltaX = 0;
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_MOVE || motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
int newX = (int) motionEvent.getX();
deltaX = oldX - newX;
oldX = newX;
}
if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
oldX = 0;
}
return deltaX < 0;
}
但是视图仍然会向右一点。有人在解决同样的问题吗?