我正在尝试做一个愚蠢的应用程序,其中使用移动HelloWorld!!
绘制的“”字符串。Canvas
字符串的位置(x_new, y_new)
只是它的旧位置(x_old, y_old)
加上事件(x, y)
返回的位置ACTION_UP
。问题是ACTION_UP
它无法识别的事件。该Log.d()
函数总是打印类似motionEvent(28254): MotionEvent{4050df70 action=4 x=354.0 y=415.0 pressure=0.20000002 size=0.26666668}
where action=4
never change 的内容。你有什么建议吗?谢谢!!
class myView extends View {
private Canvas canvas;
private int x;
private int y;
public HUDView(Context context) {
super(context);
this.x=5;
this.y=5;
}
protected void onDraw(Canvas canvas) {
this.canvas=canvas;
this.canvas.drawText("HelloWorld!!", x, y, mLoadPaint);
}
@Override
public boolean onTouchEvent( MotionEvent event) {
super.onTouchEvent(event);
Log.d("motionEvent", event.toString());
if (event.getAction()==MotionEvent.ACTION_UP){
Log.d("motionEvent", "action_up");
this.x+=(int)event.getX();
this.y+=(int)event.getY();
return true;
}
this.postInvalidate();
return true;
}
}