0

我希望在设定的持续时间后在不同的 TextViews 1 上开始相同的动画。目前我有下面的代码,但我觉得必须有更好的方法来做到这一点。

      Animation anim = AnimationUtils.loadAnimation(this, R.anim.flyin);
      play_now_but.setAnimation(anim);

      Animation anim2 = AnimationUtils.loadAnimation(this, R.anim.flyin);
      anim2.setStartOffset(250);
      story_mode_but.setAnimation(anim2);

      Animation anim3 = AnimationUtils.loadAnimation(this, R.anim.flyin);
      anim3.setStartOffset(500);
      create_puzzle_but.setAnimation(anim3);

      Animation anim4 = AnimationUtils.loadAnimation(this, R.anim.flyin);
      anim4.setStartOffset(750);
      stats_but.setAnimation(anim4);

      Animation anim5 = AnimationUtils.loadAnimation(this, R.anim.flyin);
      anim5.setStartOffset(1000);
      settings_but.setAnimation(anim5);

      Animation anim6 = AnimationUtils.loadAnimation(this, R.anim.flyin);
      anim6.setStartOffset(1250);
      about_but.setAnimation(anim6);

      anim.start();
      anim2.start();
      anim3.start();
      anim4.start();
      anim5.start();
      anim6.start();
4

1 回答 1

1

你这样做的方式没有任何问题,尽管我会在前一个动画完成后明确地开始下一个动画:

Animation anim = AnimationUtils.loadAnimation(this, R.anim.flyin);
play_now_but.setAnimation(anim);

final Animation anim2 = AnimationUtils.loadAnimation(this, R.anim.flyin);
story_mode_but.setAnimation(anim2);

final Animation anim3 = AnimationUtils.loadAnimation(this, R.anim.flyin);
create_puzzle_but.setAnimation(anim3);

final Animation anim4 = AnimationUtils.loadAnimation(this, R.anim.flyin);
stats_but.setAnimation(anim4);

final Animation anim5 = AnimationUtils.loadAnimation(this, R.anim.flyin);
settings_but.setAnimation(anim5);

final Animation anim6 = AnimationUtils.loadAnimation(this, R.anim.flyin);
about_but.setAnimation(anim6);

anim.setAnimationListener(new AnimationListener() {
    public onAnimationEnd(Animation animation) {
        anim2.start();
    }
});

anim2.setAnimationListener(new AnimationListener() {
    public onAnimationEnd(Animation animation) {
        anim3.start();
    }
});
anim3.setAnimationListener(new AnimationListener() {
    public onAnimationEnd(Animation animation) {
        anim4.start();
    }
});
anim4.setAnimationListener(new AnimationListener() {
    public onAnimationEnd(Animation animation) {
        anim5.start();
    }
});
anim5.setAnimationListener(new AnimationListener() {
    public onAnimationEnd(Animation animation) {
        anim6.start();
    }
});

anim.start();
于 2013-07-12T14:58:10.933 回答