我的应用程序中有一个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;
}
Run Code Online (Sandbox Code Playgroud)
但观点仍然偏向右侧.有人在解决同样的问题吗?