【发布时间】:2011-04-18 13:42:20
【问题描述】:
我有一个需要 onTouch 滑动事件的应用程序,例如 Iphone。他们是
- 向上滑动。
- 向下滑动。
- 向左滑动。
- 向右滑动。
我实现了 onTouch 事件如下。我得到了正确的向左和向右滑动动作。但这是实现向下和向上滑动动作的正确方法。
我的密码:
float downXValue,downYValue;
@Override
public boolean onTouchEvent(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();
downYValue = arg1.getY();
break;
}
case MotionEvent.ACTION_UP:
{
// Get the X value when the user released his/her finger
float currentX = arg1.getX();
float currentY=arg1.getY();
// going backwards: pushing stuff to the right
if (downXValue < currentX)
{
Log.d(DEBUG_TAG, "Right");
}
// going forwards: pushing stuff to the left
if (downXValue > currentX)
{
Log.d(DEBUG_TAG, "Left");
}
break;
}
}
//GestureListener is called here...
//return gestures.onTouchEvent(event);
return true;
}
谢谢。
【问题讨论】:
标签: android