即時通訊有一個應用程序需要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