Hello, i encountered the same problem and tried starting a timer with a delay that is equal to the time of the first animation. and when that timer runs out a timertask poked and in that run() I try to start a reverse animation. But it does not play.
Here is the code I used:
public class Main extends Activity {
AnimationDrawable sybAnimation;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView imageView = (ImageView)findViewById(R.id.ImageView01);
imageView.setBackgroundResource(R.anim.testanimation);
sybAnimation = (AnimationDrawable) imageView.getBackground();
imageView.post(new Starter());
}
class Starter implements Runnable {
public void run() {
sybAnimation.start();
long totalDuration = 0;
for(int i = 0; i< sybAnimation.getNumberOfFrames();i++){
totalDuration += sybAnimation.getDuration(i);
}
Timer timer = new Timer();
timer.schedule(new AnimationFollowUpTimerTask(R.id.ImageView01, R.anim.testanimation_reverse),totalDuration);
}
}
class AnimationFollowUpTimerTask extends TimerTask {
private int id;
private int animationToRunId;
public AnimationFollowUpTimerTask(int idOfImageView, int animationXML){
id = idOfImageView;
animationToRunId = animationXML;
}
@Override
public void run() {
ImageView imageView = (ImageView)findViewById(id);
imageView.setBackgroundResource(animationToRunId);
AnimationDrawable anim = (AnimationDrawable) imageView.getBackground();
anim.start();
}
}
}