使用AnimationDrawable时出现内存不足错误

时间:2014-03-07 16:58:32

标签: android animation

您好我正在尝试使用我创建动画的几个png图像创建徽标动画,并且因内存不足错误而崩溃。有谁知道解决这个问题?

继承人到目前为止我所拥有的

继承我的动画列表

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
  <item android:drawable="@drawable/intro_animation_00" android:duration="50" /> 
  <item android:drawable="@drawable/intro_animation_01" android:duration="50" />  
  <item android:drawable="@drawable/intro_animation_02" android:duration="50" /> 
  <item android:drawable="@drawable/intro_animation_03" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_04" android:duration="50" />  
  <item android:drawable="@drawable/intro_animation_05" android:duration="50" />  
  <item android:drawable="@drawable/intro_animation_06" android:duration="50" /> 
  <item android:drawable="@drawable/intro_animation_07" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_08" android:duration="50" /> 
  <item android:drawable="@drawable/intro_animation_09" android:duration="50" />  
  <item android:drawable="@drawable/intro_animation_10" android:duration="50" /> 
  <item android:drawable="@drawable/intro_animation_11" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_12" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_13" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_14" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_15" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_16" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_17" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_18" android:duration="50" />  
  <item android:drawable="@drawable/intro_animation_19" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_20" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_21" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_22" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_23" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_24" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_25" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_26" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_27" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_28" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_29" android:duration="50" />
  <item android:drawable="@drawable/intro_animation_30" android:duration="50" />
</animation-list>

继承我的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/bg"
    tools:context=".MenuActivity" >

        <ImageView
            android:id="@+id/myanimation"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@anim/intro_animation"
        />

</RelativeLayout>

继承我的活动

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_menu);
        ImageView myAnimation = (ImageView)findViewById(R.id.myanimation);
        final AnimationDrawable myAnimationDrawable
        = (AnimationDrawable)myAnimation.getDrawable();

        myAnimation.post(
        new Runnable(){

          @Override
          public void run() {
           myAnimationDrawable.start();
          }
        });

    }

1 个答案:

答案 0 :(得分:3)

尝试在您的应用标记中添加largeHeap=true 表现。

我希望这有帮助。

或尝试使用小尺寸图片。