Reputation: 1401
I have two animations in my anim/ folder. One is a one shot and the other loops.
I am trying to play the loop after the one shot is finished.
I tried using an AnimationSet, but I'm doing it wrong.
AnimationSet as = new AnimationSet(true);
Animation AnimFirst = AnimationUtils.loadAnimation(null, R.anim.oneshot);
Animation AnimSecond = AnimationUtils.loadAnimation(null, R.anim.loop);
as.addAnimation(AnimFirst);
as.addAnimation(AnimSecond);
ImageView image1 = (ImageView) findViewById(R.id.image1);
image1.startAnimation(as);
Upvotes: 0
Views: 976
Reputation: 16526
I'd go for an AnimationListener
to run your second animation once the first one is finished. Something like.-
Animation animFirst = AnimationUtils.loadAnimation(null, R.anim.oneshot);
Animation animSecond = AnimationUtils.loadAnimation(null, R.anim.loop);
final ImageView image1 = (ImageView) findViewById(R.id.image1);
animFirst.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
image1.startAnimation(animSecond);
}
});
image1.startAnimation(animFirst);
This way, you don't really need an AnimationSet, which is supposed to play a set of animations simultaneously, not in a sequence.
Upvotes: 2