【问题标题】:animation-list with 510 images causes OutOfMemoryError包含 510 个图像的动画列表导致 OutOfMemoryError
【发布时间】:2013-01-20 14:34:01
【问题描述】:

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

我按照建议使用了动画列表,但现在尝试启动应用程序时出现以下异常。

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):在 android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) 01-20 18:20:49.024:E/AndroidRuntime(24340):在 android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502) 01-20 18:20:49.024: E/AndroidRuntime(24340): 在 android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355) 01-20 18:20:49.024: E/AndroidRuntime(24340): 在 android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785) 01-20 18:20:49.024: E/AndroidRuntime(24340): 在 android.content.res.Resources.loadDrawable(Resources.java:1992) 01-20 18:20:49.024:E/AndroidRuntime(24340):在 android.content.res.Resources.getDrawable(Resources.java:660) 01-20 18:20:49.024:E/AndroidRuntime(24340):在 android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:282) 01-20 18:20:49.024: E/AndroidRuntime(24340): 在 android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:885) 01-20 18:20:49.024: E/AndroidRuntime(24340): 在 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();

【问题讨论】:

    标签: android android-animation


    【解决方案1】:

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

    【讨论】:

    • 如果我感谢您的帮助,您不会碰巧知道在此动画列表中包含 510 个项目的“快速”方法吗?
    • @litemode: 编写脚本生成文件。
    • 我尝试这样做,结果在尝试启动应用程序时出现异常,请参阅我的编辑了解详情。
    • @litemode:你的 510 张图片加起来,代表的 RAM 超出了你的空间。减少图像数量或减小图像大小。
    猜你喜欢
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 2010-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-28
    • 1970-01-01
    相关资源
    最近更新 更多