我使用矩阵
移动位图时遇到问题 case MotionEvent.ACTION_MOVE:
if (!ScaleDetector.isInProgress()) {
speedx = (event.getX() - downCorx);
speedy = (event.getY() - downCory);
matrix.postTranslate(speedx, speedy);
Log.e("000", speedx + "| " + speedy + "! ");
}
this.invalidate();
break;
该代码有效,但它加快了位图速度!
其余代码:
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(finalBitmap, matrix, null);
}
public void setBitmap(Bitmap bitmap) {
finalBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
myCanvas = new Canvas(finalBitmap);
myCanvas.drawBitmap(bitmap, 0, 0, null);
}
有没有更好的方法呢?
答案 0 :(得分:0)
case MotionEvent.ACTION_MOVE:
if (!ScaleDetector.isInProgress()) {
speedx = (event.getX() - downCorx);
speedy = (event.getY() - downCory);
// update your current position. So when ACTION_MOVE is triggered again, you actually calculate only the speed between the current and last event of ACTION_MOVE
downCorx = event.getX();
downCory = event.getY();
matrix.postTranslate(speedx, speedy);
Log.e("000", speedx + "| " + speedy + "! ");
}
this.invalidate();
break;