【问题标题】:Android RotateAnimation CompletedAndroid RotateAnimation 完成
【发布时间】:2018-07-18 19:20:26
【问题描述】:

我正在处理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();

【问题讨论】:

    标签: android animation


    【解决方案1】:
    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
    

    【讨论】:

    【解决方案2】:

    在 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多