Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/201.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 RotateAnimation不会在启动活动之前等待按钮旋转_Android_Rotateanimation - Fatal编程技术网

Android RotateAnimation不会在启动活动之前等待按钮旋转

Android RotateAnimation不会在启动活动之前等待按钮旋转,android,rotateanimation,Android,Rotateanimation,我在安卓系统中有一个ImageButton,点击时会旋转。问题在于,当用户点击它并进入下一行的新活动时,它没有完成旋转。我尝试了Thread.sleep(…)和wait(…)但是在动画开始之前,将RotateAnimation(…)与这些一起放置实际上是在休眠 我需要动画实际完成,然后进入startActivity(新意图(..) 这是密码 amazingPicsButton.setOnClickListener(new View.OnClickListener() {

我在安卓系统中有一个
ImageButton
,点击时会旋转。问题在于,当用户点击它并进入下一行的新活动时,它没有完成旋转。我尝试了
Thread.sleep(…)
wait(…)
但是在动画开始之前,将
RotateAnimation(…)
与这些一起放置实际上是在休眠

我需要动画实际完成,然后进入
startActivity(新意图(..)

这是密码

 amazingPicsButton.setOnClickListener(new View.OnClickListener() {          
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            amazingPicsSound = createRandButSound();
            amazingPicsSound.start();               
            rotateAnimation(v);

            startActivity(new Intent("com.jasfiddle.AmazingInterface.AMAZINGPICS"));            
        }
    });         
}


/** function that produces rotation animation on the View v.
 * Could be applied to button, ImageView, ImageButton, etc.
 */
public void rotateAnimation(View v){
    // Create an animation instance
    Animation an = new RotateAnimation(30, 360, v.getWidth()/2, v.getHeight()/2);

    // Set the animation's parameters
    an.setDuration(20);               // duration in ms
    an.setRepeatCount(10);                // -1 = infinite repeated
  //  an.setRepeatMode(Animation.REVERSE); // reverses each repeat
    an.setFillAfter(true);               // keep rotation after animation

    v.setAnimation(an);
    // Apply animation to the View

}

您从不要求应用程序等待动画结束后才开始新活动。 看


要了解如何使用动画监听器,动画是一个异步过程,因此如果希望在继续之前完成动画,则需要添加动画监听器,并在动画完成后执行下一行代码:

amazingPicsButton.setOnClickListener(new View.OnClickListener() {          
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        amazingPicsSound = createRandButSound();
        amazingPicsSound.start();
        rotateAnimation(v);
    }
});         
然后

public void rotateAnimation(View v){
    // Create an animation instance
    Animation an = new RotateAnimation(30, 360, v.getWidth()/2, v.getHeight()/2);

    // Set the animation's parameters
    an.setDuration(20);               // duration in ms
    an.setRepeatCount(10);                // -1 = infinite repeated
    //  an.setRepeatMode(Animation.REVERSE); // reverses each repeat
    an.setFillAfter(true);               // keep rotation after animation

    an.addAnimationListener(new AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {}

            @Override
            public void onAnimationRepeat(Animation animation) {}

            @Override
            public void onAnimationEnd(Animation animation) {
                startActivity(new Intent("com.jasfiddle.AmazingInterface.AMAZINGPICS"));
            }
        });

    v.setAnimation(an);

}
请注意,
startActivity
调用不在
AnimationListener
onAnimationEnd
方法中,而不是在将动画设置到视图中之后