我必须在 Android 中进行拖动导航。我为拖屏导航添加了代码。这不像 Android 默认那样流畅。以下代码提供了从左到右和从右到左的拖动导航,但问题是当您点击右侧然后点击左侧然后屏幕导航时。实现它的正确方法是什么。我是否需要使用相同的代码来计算 X 值?
代码下方。
// 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;
}
}
}
请指定实现它的正确方法。
提前致谢
最佳答案
你应该使用 GestureListener
关于Android - 拖屏导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4367934/