Androidで、ユーザーに回転/反転コインを描画させる方法SurfaceView
。アニメーションを使用して、フリッピングコインをで表示するのは非常に簡単ですが、同じ滑らかさでImageView
これをオンにする必要があります。SurfaceView
フリッピングアニメーションをImageView
作成して、そのコンテンツを毎回取り出して、SurfaceView
継続的に描画する方法はありますか?
2527 次
1 に答える
2
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();
}
}
}
}
于 2012-10-27T16:04:18.107 に答える