2017-08-02 124 views
0

我只是試圖插入一幀通過使用圖像創建幀動畫現在在webp格式下運行良好與下面給出的代碼片段上的Android 7.1 Oneplus3但在Android 4.1.1失敗(模擬器)與ResourcesNotFoundException說,它無法找到名稱爲animation.xml的可繪製文件夾中的xml文件。我只是在我的項目中有一個可繪製的文件夾我還添加了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(); 

提拉/ 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作爲自Gingerbread以來支持的設備,那麼對於較低的Android版本也會有任何兼容性問題? 這將是顯而易見的添加,但文件包括圖像和XML存在於項目文件。

回答

0

實際上,爲了減少應用程序大小,我用各自的webp格式替換了所有圖像,但上面的代碼動畫給了某些設備上的ResourceNotFoundException。嘗試完所有事情後,我從webp切換回png,現在動畫在所有設備上都沒有問題。所以我認爲webp格式對於框架動畫並不可靠。這是我的觀察。如果你有任何補充,請讓我知道。