Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replay a one shot animation

I want to make a one shot animation but be able to play it as many times as I want. Right now it plays only the first time.

.xml:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/p1_ch1" android:oneshot="true">
    <item 
      android:drawable="@drawable/p1_ch1_5" 
      android:duration="500"/>
    <item 
      android:drawable="@drawable/p1_ch1_4" 
      android:duration="1000"/>
    <item 
      android:drawable="@drawable/p1_ch1_5" 
      android:duration="500"/>
</animation-list>

.java:

public void handler_p1_ch1_5 (View target){
      ImageView iv = (ImageView)findViewById(R.id.p1_ch1_5);
      AnimationDrawable aw = (AnimationDrawable)iv.getBackground();
      aw.start();
}
like image 234
slipbull Avatar asked Sep 01 '11 12:09

slipbull


1 Answers

Just call aw.stop() before aw.start()

like image 74
slipbull Avatar answered Oct 04 '22 07:10

slipbull