How To Add Delay Between Animations
I'm having a trouble with animations in android. I have my animation_char.xml:
Solution 1:
Actually I've answered on this question here. You should start your second animation in onAnimationEnd
of AnimationListener of first animations. The same for second one.
Solution 2:
You should use AnimationSet class instead of AnimatorSet.
For instance
AnimationSet as = new AnimationSet(true);
as.setFillEnabled(true);
as.setInterpolator(new BounceInterpolator());
as.addAnimation(firstAnim);
as.addAnimation(secondAnim);
as.setDuration(1000);
imageView.startAnimation(as);
Solution 3:
I put this here maybe it helps someone...
I did something like this. I have 3 images that I want to fall one after the other.
note1 = findViewById(R.id.note1);
note1.setVisibility(View.INVISIBLE);
note2 = findViewById(R.id.note2);
note2.setVisibility(View.INVISIBLE);
note3 = findViewById(R.id.note3);
note3.setVisibility(View.INVISIBLE);
Setting visibility so that they are not shown initially
And then create 3 animations
AnimationslideDown= AnimationUtils.loadAnimation(this, R.anim.slide_down);
note1.startAnimation(slideDown);
finalAnimationslideDown2= AnimationUtils.loadAnimation(SplashScreen.this, R.anim.slide_down);
finalAnimationslideDown3= AnimationUtils.loadAnimation(SplashScreen.this, R.anim.slide_down);
Next step is to add the event listeners that @Divers added:
slideDown.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
note1.setVisibility(View.VISIBLE);
note2.startAnimation(slideDown2);
slideDown2.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
note3.startAnimation(slideDown3);
note2.setVisibility(View.VISIBLE);
slideDown3.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
note3.setVisibility(View.VISIBLE);
}
@OverridepublicvoidonAnimationRepeat(Animation animation) {
}
});
}
@OverridepublicvoidonAnimationRepeat(Animation animation) {
}
});
}
@OverridepublicvoidonAnimationRepeat(Animation animation) {
}
});
And that's all
My animation xml is something like
<?xml version="1.0" encoding="utf-8"?><setxmlns:android="http://schemas.android.com/apk/res/android"><translateandroid:duration="800"android:fromXDelta="0%"android:fromYDelta="-50%p"
/><alphaandroid:duration="500"android:fromAlpha="0.1"android:toAlpha="1.0"
/></set>
Post a Comment for "How To Add Delay Between Animations"