我有一台GirdView和一台onTouchListener,我想知道当有人在屏幕上滑动手指时的方向,我可以轻松地左右移动,但我也想上下移动。
但我的问题是..
float currentX;
float currentY;
@Override
public boolean onTouch(View v, MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.d("Showpatch", "Down Triggered " + x + ", " + y);
currentX = x;
currentY = y;
break;
case MotionEvent.ACTION_UP:
Log.d("Showpatch", "Up Triggered" + x + ", " + y);
Log.d("Showpatch", "Testing Left... " + x + ", " + y);
if (currentX > x) {
Log.d("Showpatch", "Moved Left");
return false;
}
Log.d("Showpatch", "Testing Right... " + x + ", " + y);
if (currentX < x) {
Log.d("Showpatch", "Moved Right");
return false;
}
Log.d("Showpatch", "Testing Down... " + x + ", " + y);
if (currentY < y) {
Log.d("Showpatch", "Moved Down");
return false;
}
Log.d("Showpatch", "Testing Up... " + x + ", " + y);
if (currentY < y) {
Log.d("Showpatch", "Moved Up");
return false;
}
break;
}
return false;
}正如我所说的,它可以毫无问题地向左和向右移动,但它永远不会检测到向上或向下,因为它在到达up/down语句之前会触发left/right,除非您准确地上下移动手指,否则它不会工作……
有没有一种方法可以让用户向上或向下滑动?
非常感谢您的帮助,谢谢。
发布于 2011-06-19 05:22:30
我相信手势监听器可以帮助你做到这一点,它是在1.6中引入的
http://developer.android.com/resources/articles/gestures.html
干杯托比亚斯
https://stackoverflow.com/questions/6398880
复制相似问题