我有一个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;
}
正如我所说的那样左右没有问题,但它从未检测到向上或向下,因为它在向上/向下声明之前向左/向右发射,除非你的手指完全上下移动它没有工作......
有没有办法让用户向上或向下滑动?
非常感谢任何帮助,谢谢。
答案 0 :(得分:2)
我相信Gesture Listener可以帮助你,它已经在1.6中引入了
http://developer.android.com/resources/articles/gestures.html
欢呼声 托拜厄斯