框架动画因资源$ NotFoundException而失败

时间:2017-08-02 05:34:29

标签: android xml animation

我只是想尝试使用现在使用webp格式的图像创建逐帧动画,该格式在Android 7.1 Oneplus3上使用下面给出的代码片段运行良好但在Android 4.1.1(模拟器)上使用ResourcesNotFoundException表示无效它在drawable文件夹中找不到名为animation.xml的xml文件。我在我的项目中只有一个drawable文件夹我还添加了vectorDrawables.useSupportLibrary = true作为stackoverflow线程建议之一,我清理了项目并尝试了android:largeHeap =" true"即使图像尺寸太小但错误仍然存​​在于4.1.1 android api。

imageView = (ImageView) findViewById(R.id.animx);

imageView.setBackgroundResource(R.drawable.animation); // error happening here
AnimationDrawable anim = (AnimationDrawable) imageView.getBackground(); 
anim.start();

drawable / animation.xml文件如下所示:

    <?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item android:drawable="@drawable/spinners1" android:duration="70" />
    <item android:drawable="@drawable/spinners2" android:duration="70" />
    <item android:drawable="@drawable/spinners3" android:duration="70" />
    <item android:drawable="@drawable/spinners4" android:duration="70" />
</animation-list>

撞车的原因是什么?为什么它只发生在Android 4.1.1中?如果我使用vectorDrawables.useSupportLibrary = true因为我支持姜饼以来的设备,那么对于较低的Android版本是否会有任何兼容性问题? 很明显,添加但包含images和xml的文件存在于项目文件中。

1 个答案:

答案 0 :(得分:0)

实际上为了减少应用程序大小,我已经用相应的webp格式替换了所有图像,但是上面的代码中的动画在某些设备上给出了ResourceNotFoundException。尝试了一切后,我从webp切换回pngs,现在动画在所有设备上都没有问题。所以我认为webp格式对于帧动画来说是不可靠的。这是我的观察。如果您有任何要添加的内容,请告诉我们。