I am facing a problem in Frame by Frame animation in Android. Actually i am having lots of images as frames, for that i have crated different animation-list files for different animation. On the main screen i am having one background image on which i am having different buttons for different animation. I am done with animation also, but when i click 2nd time on the buttons the animation does not work. Means it is working only once. I don’t why this is happening. Here is some code snippet of my project.
Animation List File:-
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true">
<item android:drawable="@drawable/cat_angry0000" android:duration="50" />
<item android:drawable="@drawable/cat_angry0001" android:duration="50" />
<item android:drawable="@drawable/cat_angry0002" android:duration="50" />
<item android:drawable="@drawable/cat_angry0003" android:duration="50" />
<item android:drawable="@drawable/cat_angry0004" android:duration="50" />
<item android:drawable="@drawable/cat_angry0005" android:duration="50" />
<item android:drawable="@drawable/cat_angry0006" android:duration="50" />
<item android:drawable="@drawable/cat_angry0007" android:duration="50" />
<item android:drawable="@drawable/cat_angry0008" android:duration="50" />
<item android:drawable="@drawable/cat_angry0009" android:duration="50" />
<item android:drawable="@drawable/cat_angry0010" android:duration="50" />
<item android:drawable="@drawable/cat_angry0011" android:duration="50" />
<item android:drawable="@drawable/cat_angry0012" android:duration="50" />
<item android:drawable="@drawable/cat_angry0013" android:duration="50" />
<item android:drawable="@drawable/cat_angry0014" android:duration="50" />
<item android:drawable="@drawable/cat_angry0015" android:duration="50" />
<item android:drawable="@drawable/cat_angry0016" android:duration="50" />
<item android:drawable="@drawable/cat_angry0017" android:duration="50" />
<item android:drawable="@drawable/cat_angry0018" android:duration="50" />
<item android:drawable="@drawable/cat_angry0019" android:duration="50" />
<item android:drawable="@drawable/cat_angry0020" android:duration="50" />
<item android:drawable="@drawable/cat_angry0021" android:duration="50" />
<item android:drawable="@drawable/cat_angry0022" android:duration="50" />
<item android:drawable="@drawable/cat_angry0023" android:duration="50" />
<item android:drawable="@drawable/cat_angry0024" android:duration="50" />
<item android:drawable="@drawable/cat_angry0025" android:duration="50" />
</animation-list>
Code:-
ImageView rocketImage;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.catlayout);
rocketImage = (ImageView) findViewById(R.id.backgroundCat);
rocketImage.setImageBitmap(null);
rocketImage.setBackgroundResource(R.anim.angry_tail_animation);
}
public void headButtonClicked(View v) {
final AnimationDrawable mailAnimation = (AnimationDrawable) mMailTab.getBackground();
mMailTab.post(new Runnable() {
public void run() {
if ( mailAnimation != null ) mailAnimation.start();
}
});
}
headButtonClicked is a button placed by me for starting animation. It work only once. If anybody having any idea that how to resolve this problem please kindly help me.
Thanks
In your animation xml file you have added the attribute
android:oneshot="true"which means you are wanting the Animation to be played only once. For playing it again you should make itandroid:oneshot="false"UPDATE:
If you want to start the Animation everytime you click the button you have to call the
animation.stop();for the previous started Animation if Running. Something like this,