I’m trying to perform frame by frame animation in android. For this task I created an xml file called “anim.xml” like this:
<?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/square0" android:duration="100" />
<item android:drawable="@drawable/square1" android:duration="100" />
<item android:drawable="@drawable/square2" android:duration="100" />
<item android:drawable="@drawable/square3" android:duration="100" />
<item android:drawable="@drawable/square4" android:duration="100" />
<item android:drawable="@drawable/square5" android:duration="100" />
</animation-list>
Then at a frame layout that I have defined, I tried to set it as background and start it at onCreate like this:
FrameLayout imgView = (FrameLayout)findViewById(R.id.frameLayout1);
imgView.setBackgroundResource(R.drawable.anim);
AnimationDrawable anim = (AnimationDrawable) imgView.getBackground();
anim.start();
What I’m experiencing is the first frame only, but what I’m going for is an animation of squares to be on a loop. Do you have any opinions regarding what I have done wrong ?
Cheers.
I’ve experience issues before when trying to get animations to start in the onCreate method. Try repalcing your last line with something like:
This will essentialy make you animation start after onCreate has executed.