I'd like to make a Animation Drawable with 18 images in Android Studio, but when I tried to run it, the application stopped working and I gave it to Android Monitor : < p>
03-16 16:58:26.531 12973-12973/genesysgeneration.animation E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
at android.content.res.Resources.loadDrawable(Resources.java:1940)
at android.content.res.Resources.getDrawable(Resources.java:664)
at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:280)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:867)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:804)
at android.content.res.Resources.loadDrawable(Resources.java:1925)
at android.content.res.Resources.getDrawable(Resources.java:664)
at android.support.v7.widget.ResourcesWrapper.getDrawable(ResourcesWrapper.java:128)
at android.support.v7.widget.TintResources.getDrawable(TintResources.java:45)
at android.view.View.setBackgroundResource(View.java:11695)
at android.support.v7.widget.AppCompatImageView.setBackgroundResource(AppCompatImageView.java:86)
at genesysgeneration.animation.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:4466)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
I was confused by this, because I did not know where the error was and was not accusing anything, so I decided to execute only one image of my animation ... RESULTS !!!
I tried 2, 3, 4 ... until 15 everything worked out:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/an01" android:duration="100"></item>
<item android:drawable="@drawable/an02" android:duration="100"></item>
<item android:drawable="@drawable/an03" android:duration="100"></item>
<item android:drawable="@drawable/an04" android:duration="100"></item>
<item android:drawable="@drawable/an05" android:duration="100"></item>
<item android:drawable="@drawable/an06" android:duration="100"></item>
<item android:drawable="@drawable/an07" android:duration="100"></item>
<item android:drawable="@drawable/an08" android:duration="100"></item>
<item android:drawable="@drawable/an09" android:duration="100"></item>
<item android:drawable="@drawable/an10" android:duration="100"></item>
<item android:drawable="@drawable/an11" android:duration="100"></item>
<item android:drawable="@drawable/an12" android:duration="100"></item>
<item android:drawable="@drawable/an13" android:duration="100"></item>
<item android:drawable="@drawable/an14" android:duration="100"></item>
<item android:drawable="@drawable/an15" android:duration="100"></item>
</animation-list>
When I put 16 images, it gave me an error again ...
I thought it could be a mistake in the images properly speaking, so I jumped to 16 and went to 17 ... Error again !!! Same thing with 18.
Result, I suspected that it was not an error in the images, but that it was some kind of limit of the total number of frames. I modified the animation-list for the following:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/an01" android:duration="100"></item>
<item android:drawable="@drawable/an02" android:duration="100"></item>
<item android:drawable="@drawable/an03" android:duration="100"></item>
<item android:drawable="@drawable/an04" android:duration="100"></item>
<item android:drawable="@drawable/an05" android:duration="100"></item>
<item android:drawable="@drawable/an06" android:duration="100"></item>
<item android:drawable="@drawable/an07" android:duration="100"></item>
<item android:drawable="@drawable/an08" android:duration="100"></item>
<item android:drawable="@drawable/an09" android:duration="100"></item>
<item android:drawable="@drawable/an10" android:duration="100"></item>
<item android:drawable="@drawable/an11" android:duration="100"></item>
<item android:drawable="@drawable/an12" android:duration="100"></item>
<item android:drawable="@drawable/an16" android:duration="100"></item>
<item android:drawable="@drawable/an17" android:duration="100"></item>
<item android:drawable="@drawable/an18" android:duration="100"></item>
</animation-list>
The images 16, 17 and 18 worked, so I suspected that it was really a limit of 15 frames.
I would like to know if it is a limit and if there is a way to increase it or even to do an armengue to display one animation right after the other. Thank you!
Activity code:
package genesysgeneration.animation;
import android.graphics.drawable.AnimationDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private AnimationDrawable animation;
private ImageView ivInvisible;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ivInvisible=(ImageView)findViewById(R.id.ivInvisible);
ivInvisible.setBackgroundResource(R.drawable.an00);
animation=(AnimationDrawable)ivInvisible.getBackground();
}
public boolean onTouchEvent(MotionEvent event){
if (event.getAction()==MotionEvent.ACTION_DOWN){
animation.start();
return true;
}
return super.onTouchEvent(event);
}
}