我有一个需要ontouch滑动事件的应用程序,如在Iphone中.他们是
>向上滑动.
>向下滑动.
>向左滑动.
>向右滑动.
我实现了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; }
谢谢.
解决方法:
关于什么…
if (downYValue < currentY){ Log.d(DEBUG_TAG, "Down");}
你确定你写了上面的代码吗?
编辑
好的,我相信你.你要做的基本上是:
double sizeInX = Math.abs(downXValue - currentX);double sizeInY = Math.abs(downYValue - currentY);if( sizeInX > sizeInY ){ // you better swipe horizontally} else { // you better swipe vertically}
总结 以上是内存溢出为你收集整理的Android 0nTouch事件问题[向下轻扫]全部内容,希望文章能够帮你解决Android 0nTouch事件问题[向下轻扫]所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)