写真のリンク: http://imgur.com/a/3Q2jQ
Canvas を使用して Android アプリケーションのアニメーションを作成しています。すべてが移動または回転し、すべてのアニメーションが完璧な onDraw メソッドがあります。しかし、2 番目の画像のようにアニメーションを変更しようとすると、1 ~ 2 秒間スタックしてから 3 番目の画像に移動します。ご覧のとおり、アプリケーションは天気に関するもので、すべての条件がアニメーションです。
これを解決する方法はありますか?
これは onDraw メソッドの最初の画像です。
else {
if (unknown == null) {
recycleBitmap();
condition = 0;
unknown = BitmapFactory.decodeResource(getResources(),
R.drawable.unknown);
width = getLayoutParams().width;
height = getLayoutParams().height;
width = width - (width / 7);
height = height - (height / 7);
unknown = Bitmap.createScaledBitmap(unknown, (int) width,
(int) height, true);
initWeatherIcon();
}
drawUnknown1((getLayoutParams().width - unknown.getWidth()) / 2,
((getLayoutParams().height - unknown.getHeight()) / 2),
canvas);
これは 3 番目の画像のコードです。
else if (condition == 6) {
matrix.reset();
matrix.setTranslate(getLayoutParams().height / 2,
icon.getHeight() / 3);
matrix.postRotate(x, getLayoutParams().width / 2
+ getLayoutParams().width / 4,
icon.getHeight() / 3 + icon.getHeight() / 2);
x++;
RectF rect4 = new RectF(100, 100, 100, 100);
matrix.mapRect(rect4);
canvas.drawBitmap(icon, matrix, new Paint());
drawCloudSun(
0,
getLayoutParams().height
- (getLayoutParams().height / 2 + getLayoutParams().height / 4),
canvas);
invalidate();
アニメーションを呼び出す If-else があります。アプリケーションを起動するとunknown.pngと呼ばれますが、条件がCloudyに変更されると、適切なif-elseステートメントに入り、そこで問題が発生します。