即时通讯有一个应用程序需要onTouch刷卡事件,如Iphone。他们是Android的0nTouch事件问题[向下滑动并向上滑动]
- 向上滑动。
- 向下滑动。
- 向左滑动。
- 向右滑动。
我实现了onTouch事件如下。并且我正确地滑动左右行动。但是,这是实施滑动向下和向上行为的正确方法。
mycode的:
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;
}
谢谢。
嗨crisitain感谢我已经添加了答复,但它会导致与滑动下来,向左或向右滑动操作。它会导致2个行动。 – bHaRaTh 2011-04-18 05:36:54
编辑我的答案...好运 – Cristian 2011-04-18 05:43:06
您好cristain我会尝试这个..谢谢 – bHaRaTh 2011-04-18 05:45:58