我试图把图象从我触及的点点点移至点,但情况却不好。
Render.java(校友班)
public void run() {
Canvas canvas;
while (runFlag) {
long now = System.currentTimeMillis();
long elapsedTime = now - prevTime;
if (elapsedTime > 30){
prevTime = now;
if (touched ==true) {
matrix.postTranslate(touched_x, touched_y);
touched =false;
}
}
canvas = null;
try {
canvas = surfaceHolder.lockCanvas(null);
synchronized (surfaceHolder) {
if (touched ==true) {
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(picture, matrix, null);
touched = false;
}
}
}
finally {
if (canvas != null) {
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
在此,我打着旗帜,在绘画时加以检查......似乎不是好主意。
View.java (SurfaceView class)
public boolean onTouchEvent(MotionEvent event) {
touched_x = event.getX();
touched_y = event.getY();
int action = event.getAction();
switch(action){
case MotionEvent.ACTION_DOWN:
touched = true;
break;
case MotionEvent.ACTION_MOVE:
touched = true;
break;
case MotionEvent.ACTION_UP:
touched = false;
break;
case MotionEvent.ACTION_CANCEL:
touched = false;
break;
case MotionEvent.ACTION_OUTSIDE:
touched = false;
break;
default:
}
return false;
}