[英]Android RotateAnimation Completed
I am working on a RotateAnimation
. 我正在
RotateAnimation
上工作。 I started to rotate the image but I want to know when animation completes. 我开始旋转图像,但是我想知道动画何时完成。 How will I know when the animation ends?
我怎么知道动画何时结束?
Below is my rotation image code. 以下是我的旋转图片代码。
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();
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
// 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.