1

我正在创建一个 android 应用程序,它为每个活动都有背景动画。我曾经AnimationDrawable setBackgroundResource(anim.xml)运行动画 xml 文件并且工作正常。问题是,当我在设备上进行测试时,有些设备会FATAL EXEPTION告诉 我bitmap size exeeds VM budget(out of memory)

所以我上网并找到了一些解决方案,比如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>
4

0 回答 0