私はAndroidアプリケーションを作成していますが、各アクティビティの背景アニメーションがあります。以前AnimationDrawable
setBackgroundResource(anim.xml)
はアニメーションxmlファイルを実行していましたが、正常に動作します。問題は、デバイスでテストすると、一部のデバイスからFATAL EXEPTION
そのことがわかり
bitmap size exeeds VM budget(out of memory)
ます。
そこで、Webサーフィンをしanimation.setCallbacks(null)
て、アニメーションを実行する前に実行する、ビットマップを(プログラムで)縮小する、ドローアブルのサイズを変更するなどの解決策を見つけました。それらを試しましたが、ヒープが少ないデバイスで同じエラーが発生するものはほとんどありません。
だから私は何か間違ったことをしているのか、何かを逃しているのか知りたいですか?この問題に対する他の解決策はありますか?
//animation
private void animate() {
imgView = (ImageView)findViewById(R.id.imageView1);
imgView.setVisibility(ImageView.VISIBLE);
imgView.setBackgroundResource(R.drawable.level_animation);
frameAnimation = (AnimationDrawable) imgView.getBackground();
if (frameAnimation.isRunning()) {
frameAnimation.stop();
}
else {
frameAnimation.stop();
frameAnimation.start();
}
}
xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true" >
<item android:drawable="@drawable/top_anim1" android:duration="200" />
<item android:drawable="@drawable/top_anim2" android:duration="200" />
<item android:drawable="@drawable/top_anim3" android:duration="200" />
<item android:drawable="@drawable/top_anim4" android:duration="200" />
<item android:drawable="@drawable/top_anim5" android:duration="200" />
</animation-list>