Android的onFling没有响应 [英] Android onFling not responding
问题描述
我是新首先到Android所以想到的任何错误,新手首先
I am new to android first of all so think of any newbie mistakes first
我想在我的code添加一扔功能。
I am trying to add a fling function in my code.
public class MainGamePanel extends SurfaceView implements
SurfaceHolder.Callback, OnGestureListener {
private MainThread thread;
private Droid droid;
private Droid droid2;
private static final String TAG = gameView.class.getSimpleName();
private GestureDetector gestureScanner;
public MainGamePanel(Context context){
super(context);
getHolder().addCallback(this);
droid = new Droid(BitmapFactory.decodeResource(getResources(), R.drawable.playerbox2), 270, 300);
droid2 = new Droid(BitmapFactory.decodeResource(getResources(), R.drawable.playerbox2), 50, 300);
thread = new MainThread(getHolder(), this);
setFocusable(true);
gestureScanner = new GestureDetector(this);
}
public boolean onTouchEvent(MotionEvent event){
return gestureScanner.onTouchEvent(event);
}
@Override
protected void onDraw(Canvas canvas){
canvas.drawColor(Color.BLACK);
droid.draw(canvas);
droid2.draw(canvas);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
droid.setX(50);
droid.setY(50);
Log.d(TAG, "Coords: x=" + e1.getX() + ",y=" + e2.getY());
return true;
}
@Override
public boolean onDown(MotionEvent e) {
droid2.setX((int)e.getX());
droid2.setY((int)e.getY());
Log.d(TAG, "Coords: x=" + e.getX() + ",y=" + e.getY());
return false;
}
我得到了gestureListener一起工作:onDown,onLong preSS和OnShow中preSS
I got the gestureListener to work with: onDown, onLongPress, and onShowPress.
但我不能与onFling,onSingleTapUp和onScroll任何回应。
But i can't get any response with onFling, onSingleTapUp, and onScroll.
什么错误,我在做什么?它有什么关系的看法?
What mistake am I making? does it have to do with views?
我不知道是什么code会看到有用的....所以任何建议将是多少AP preciated。 谢谢!
I don't know what code would be useful to see.... so any suggestions would be much appreciated. Thank You!
推荐答案
onDown
的 onFling
事件之前被称为。
如果您在 onDown返回false
方法,运动事件传播将停止。
onDown
is called before the onFling
event.
If you return false in onDown
method, the motion event propagation will stop.
尝试改变在
在返回false
返回true onDown 年底code>方法。
Try to change return false
in return true
at the end of onDown
method.
返回值的解释,有点钝,在输入活动该开发指南的页面。 (向下滚动下面的例子中code看)。
The return values are explained, somewhat obtusely, in the Input Events page of the Dev guide. (scroll down below the example code to see).
这篇关于Android的onFling没有响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!