2
在Android中,如何在SurfaceView
上绘制旋转/翻转硬币wrt用户。使用动画并在ImageView
中显示翻转硬币非常容易,但我需要在SurfaceView
上使用相同的平滑度。有没有什么方法可以在ImageView
中翻动动画,然后在每个瞬间取出它的内容,然后在SurfaceView
上连续绘制它?Android平滑地旋转surfaceView相对于用户
在Android中,如何在SurfaceView
上绘制旋转/翻转硬币wrt用户。使用动画并在ImageView
中显示翻转硬币非常容易,但我需要在SurfaceView
上使用相同的平滑度。有没有什么方法可以在ImageView
中翻动动画,然后在每个瞬间取出它的内容,然后在SurfaceView
上连续绘制它?Android平滑地旋转surfaceView相对于用户
您可以使用Matrix类来执行绘制位图上的这些操作。
像
Paint paint = new Paint();
paint.setAntiAlias(true);
Matrix needleTransMatrix = new Matrix();
needleTransMatrix.postRotate(rotationAngle,needleImage.getWidth()/2,needleImage.getHeight());
needleTransMatrix.postTranslate(centerX+METER_OFFSET-needleImage.getWidth()/2, centerY-needleImage.getHeight());
Matrix dialTransMatrix = new Matrix();
dialTransMatrix.postRotate(rotationAngle,dialImage.getWidth()/2,dialImage.getHeight()/2);
dialTransMatrix.postTranslate(METER_OFFSET,0);
canvas.drawBitmap(bgImage, METER_OFFSET, 0, paint);
canvas.drawBitmap(dialImage, dialTransMatrix, paint);
canvas.drawBitmap(needleImage, needleTransMatrix, paint);
以下是引出线,对此,我是在谈论
private class AnimationThread extends Thread{
private boolean isRunning = true;
private int destinationNeedlePosition = NEEDLE_POSITION_ENQURIES;
public AnimationThread(int destinationNeedlePosition) {
this.destinationNeedlePosition = destinationNeedlePosition;
}
public void cancelAnimation(){
isRunning = false;
}
@Override
public void run() {
int destinationAngle = destinationNeedlePosition *45;
while(isRunning && destinationAngle != rotationAngle){
if(destinationAngle > rotationAngle)
rotationAngle++;
else
rotationAngle--;
postInvalidate();
try {
sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
烨我试图使用矩阵可以使用在由scalling一次只得到一个瞬间..不会给你一个平滑的翻转感觉! – pvn
您需要创建一个可以从一个位置转换到另一个位置并插入位置的线程。同样的事情,我已经这样做了旋转米针。 –
你为什么使用2个矩阵? – pvn