Two animations with a delay of 1 second between

I want to create a splash screen for Android, where the logo will be animated twice:

  • Fly from left to center
  • After 1 second, fly from the center to the right

The first one works well:

Animation animLeft2Center = AnimationUtils.loadAnimation(this, R.anim.translate_left_to_center);
mLogo.startAnimation(animLeft2Center);

But I do not get the second animation.

Animation animCenter2Right = AnimationUtils.loadAnimation(this, R.anim.translate_center_to_right);
mLogo.startAnimation(animCenter2Right);

How to set a delay of 1 second between both, and then start the second animation?

I could not find something like setStartDelay, and also did not start both animations one after another.

+4
source share
1 answer

Try this as follows:

Animation animLeft2Center = AnimationUtils.loadAnimation(this, R.anim.translate_left_to_center);

mLogo.startAnimation(animLeft2Center);  
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
  @Override
  public void run() {
    //Do something after 1 second
      Animation animCenter2Right = AnimationUtils.loadAnimation(this, R.anim.translate_center_to_right);
      mLogo.startAnimation(animCenter2Right);
  }
}, 1000);
+4
source

Source: https://habr.com/ru/post/1625708/


All Articles