我必须在Android中进行拖动导航。我添加了拖动屏幕导航的代码。这不像Android默认那样流畅。下面的代码给出了从左到右和从右到左的拖动导航,但问题是当你点击右侧然后到左侧时,屏幕也会导航。什么是实现它的正确途径。我是否需要使用相同的代码来计算X值?
下面的代码。Android - 拖动屏幕导航
// On Drag Navigation
public boolean onTouch(View arg0, MotionEvent arg1) {
// Get the action that was done on this touch event
switch (arg1.getAction())
{
case MotionEvent.ACTION_DOWN:
{
// store the X value when the user's finger was pressed down
downXValue = arg1.getX();
break;
}
case MotionEvent.ACTION_UP:
{
// Get the X value when the user released his/her finger
float currentX = arg1.getX();
// Going Backward: pushing stuff to the right
if (downXValue < currentX)
{
Intent lIntent = new Intent(getApplicationContext(), previousScreen.class);
startActivity(lIntent);
finish();
}
// Going Forward: pushing stuff to the left
if (downXValue > currentX)
{
Intent lIntent = new Intent(getApplicationContext(), nextScreen.class);
startActivity(lIntent);
finish();
}
break;
}
}
}
请指定实现它的正确方法。
在此先感谢