Zoker
Zoker

Reputation: 2059

Two animations with 1 second delay inbetween

I want to built a splashscreen for android, where the logo is animated two times:

The first thing works well:

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

But I don't get the second animation to work.

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

How can I set a delay of 1 second between both and then start the second animation?

I couldn't find something like setStartDelay and also it does not fire both animations after each other.

Upvotes: 4

Views: 768

Answers (1)

Rohit Sharma
Rohit Sharma

Reputation: 2017

Try to do it in this way:

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);

Upvotes: 4

Related Questions