Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
等待来自不同类的Android动画_Android_Animation - Fatal编程技术网

等待来自不同类的Android动画

等待来自不同类的Android动画,android,animation,Android,Animation,我的问题是,我想等到动画完成后再开始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

我的问题是,我想等到动画完成后再开始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;
}
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();
    }
}
我的onClick函数:

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

可以通过在动画上设置一个。设置侦听器并在回调中启动活动

编辑:
如果<代码> TUR1从多个地方被调用,考虑将动画侦听器作为参数发送给这个方法,以便每个调用方都可以设置自己的侦听器。

我尝试过,但是问题是我有大约6个类使用动画,我只希望它在一定的条件下打开结束屏幕。这6个类别中的每一个都不同。参见上面的“编辑”部分。将
turn1(视图视图)
修改为
turn1(视图,Animation.AnimationListener侦听器)
,然后从
turnGear()调用它。对于动画结束时不需要执行任何操作的地方,只需传递null,并且不要在
turn1()
内设置它。通过此建议,您刚刚解决了我的另一个问题,我将尝试一些方法,并告诉您它是否有效:)我无法正常工作,但您帮了我很大的忙!我在Top Post中添加了第二个动画。我试图合并它们,但不知道如何。。。编辑:我试着再解释一下。。。我必须按下一个应该旋转的按钮。每个按钮都应该在“跟踪器”上,这样我就能看到他旋转了多远。我的目标是,如果它们都在180°上,则端屏应该打开。