我必須在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;
}
}
}
請指定實現它的正確方法。
在此先感謝