包含510个图像的动画列表会导致OutOfMemoryError

时间:2013-01-20 14:34:02

标签: android android-animation

我已经提供了510张图片(让我们通过animation0510将它们称为animation0000)并希望创建一个动画图像视图,可以连续循环遍历所有这些图像。

我使用了动画列表,但是在尝试启动应用程序时,我现在遇到以下异常。

  

01-20 18:20:49.024:E / AndroidRuntime(24340):致命异乎寻常:主要   01-20 18:20:49.024:E / AndroidRuntime(24340):   java.lang.OutOfMemoryError 01-20 18:20:49.024:   E / AndroidRuntime(24340):at   android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)01-20   18:20:49.024:E / AndroidRuntime(24340):at   android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)   01-20 18:20:49.024:E / AndroidRuntime(24340):at   android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)   01-20 18:20:49.024:E / AndroidRuntime(24340):at   android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)   01-20 18:20:49.024:E / AndroidRuntime(24340):at   android.content.res.Resources.loadDrawable(Resources.java:1992)01-20   18:20:49.024:E / AndroidRuntime(24340):at   android.content.res.Resources.getDrawable(Resources.java:660)01-20   18:20:49.024:E / AndroidRuntime(24340):at   android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:282)   01-20 18:20:49.024:E / AndroidRuntime(24340):at   android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:885)   01-20 18:20:49.024:E / AndroidRuntime(24340):at   android.graphics.drawable.Drawable.createFromXml(Drawable.java:822)

动画列表中的每个项目如下所示:

    <item
    android:drawable="@drawable/z_animation0123"
    android:duration="20"/>

并且ImageView包含如下:

<ImageView 
        android:id="@+id/zzz_animation_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/baby_logo_animation"
        android:layout_centerHorizontal="true"
        />

动画在onActivity中启动,如下所示:

    // Start zzz animation
    ImageView zImageView = (ImageView) findViewById(R.id.zzz_animation_view);
    zImageView.setBackgroundResource(R.drawable.z_complete_animation);

    AnimationDrawable zAnimation = (AnimationDrawable) zImageView.getBackground();
    zAnimation.start();

1 个答案:

答案 0 :(得分:0)

创建an <animation-list> drawable resource指向这510张图片以及每张图片应在屏幕上显示多长时间。在android:oneshot="false"元素上使用<animation-list>让它循环播放。然后,生成的资源可以与ImageView小部件一起使用。