安卓旋转动画完成

3

我正在处理一个RotateAnimation。我已经开始旋转图像,但我想知道动画何时完成。如何知道动画何时结束?

以下是我的旋转图像代码。

RotateAnimation rotateanimation = new RotateAnimation(StartPoint,
                    EndPoint, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            rotateanimation.setDuration(1000);
            rotateanimation.setRepeatCount(0);
            rotateanimation.setRepeatMode(Animation.REVERSE);
            rotateanimation.setFillAfter(true);
            rotateImage.setAnimation(rotateanimation);
            rotateanimation.start();
            relative.invalidate();
2个回答

3
Use Animation Listener as:

implements animation listener in activity
and then :
*rotateanimation.setAnimationListener(MainActivity.this);
*after that you will find on
    public void onAnimationEnd(Animation animation)
{
//Toast here on animation ends
}

http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html

http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html - Androider
很高兴为您服务 @user123456 - Androider

0

Kotlin 中的相同答案:

 // Animate using Code
            val rotateAnimation = RotateAnimation(
                    0f, 359f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f

            )
            rotateAnimation.duration = 300
            rotateAnimation.repeatCount = 2

            //Either way you can add Listener like this
            rotateAnimation.setAnimationListener(object : Animation.AnimationListener {

                override fun onAnimationStart(animation: Animation?) {
                }

                override fun onAnimationRepeat(animation: Animation?) {
                }

                override fun onAnimationEnd(animation: Animation?) {

                    val rand = Random()
                    val ballHit = rand.nextInt(50) + 1
                    Toast.makeText(context, "ballHit : " + ballHit, Toast.LENGTH_SHORT).show()
                }
            })

            ivBall.startAnimation(rotateAnimation)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接