我的问题是我想等到我的动画完成之后才开始Endscreen活动。问题是我通过另一个类的函数调用了动画。
轮到我的动画功能:
public void turn1(View view){
RotateAnimation rotate = new RotateAnimation(DegreesGear1 ,DegreesGear1 + 90 , Animation.RELATIVE_TO_SELF, 0.5f ,Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setInterpolator(new LinearInterpolator());
rotate.setDuration(400);
rotate.setFillEnabled(true);
rotate.setFillAfter(true);
view.startAnimation(rotate);
DegreesGear1 = DegreesGear1 + 90;
}
public void turn2(View view){
RotateAnimation rotate = new RotateAnimation(DegreesGear2 ,DegreesGear2 + 90 , Animation.RELATIVE_TO_SELF, 0.5f ,Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setInterpolator(new LinearInterpolator());
rotate.setDuration(400);
rotate.setFillEnabled(true);
rotate.setFillAfter(true);
view.startAnimation(rotate);
DegreesGear2 = DegreesGear2 + 90;
}
我的onClick功能:
public void turnGear(View v){
ImageButton gear1 = (ImageButton) findViewById(R.id.Gear1);
if (DegreesGear1 == 360) {
DegreesGear1 = 0;
}
turn1(gear1);
final TextView viewCounter = (TextView) findViewById(R.id.TextViewMoveNumber);
turnCounter ++;
viewCounter.setText (String.valueOf(turnCounter));
if (DegreesGear1 == 180) {
Intent EndScreen = new Intent (this, EndScreen.class);
startActivity(EndScreen);
finish();
}
}
答案 0 :(得分:0)
您可以通过在动画上设置AnimationListener来实现。设置监听器并在onAnimationEnd回调中启动活动。
编辑:
如果从多个地方调用turn1
,请考虑将动画侦听器作为参数发送到此方法,以便每个调用者都可以设置自己的侦听器。