RotateAnimation 获取图像的当前角度

RotateAnimation Get Current angle of image

我有一个旋转动画的问题。

第一。
动画中是否有监听器?
开始,开始动画
重复,重复动画
停止,停止动画。

但是没有动画侦听器来检查进行中。

秒,
是否还有其他获取图像的当前旋转角度?

我想,ImageView是通过rotationAnimation函数旋转的。
所以我做了一个计时器线程和 运行 1second

'''
timer = new Timer();
       timerTask = new TimerTask() {
       public void run(){
       Log.e("LOG",  " [angle]: " + String.format("%3.1f",  rotateImage.getRotation());
    }
};
timer.schedule(timerTask, 0, 1000);

'''

但是,我在旋转过程中看不到更改的值。

旋转时如何获取当前角度?

谢谢。

对于旋转动画,有如下图:

RotateAnimation rotateAnimation = new RotateAnimation();
rotateAnimation.setAnimationListener(new Animation.AnimationListener() {
  @Override
  public void onAnimationStart(Animation animation) {

  }

  @Override
  public void onAnimationEnd(Animation animation) {

  }

  @Override
  public void onAnimationRepeat(Animation animation) {

  }
});

您还可以使用对象动画器来设置旋转动画:

ObjectAnimator rotateAnimation = ObjectAnimator.ofFloat(targetView, View.ROTATION, startAngle, endAngle);
rotateAnimation.addListener(new Animator.AnimatorListener() {
  @Override
  public void onAnimationStart(Animator animation) {

  }

  @Override
  public void onAnimationEnd(Animator animation) {

  }

  @Override
  public void onAnimationCancel(Animator animation) {

  }

  @Override
  public void onAnimationRepeat(Animator animation) {

  }
});

要获取 ImageView 的角度,只需使用 imageView.getRotation(); 这将为您提供当前旋转角度的 int 值。

你也不需要Timer因为ObjectAnimator和rotateAnimator都为你提供了时间控制:

rotateAnimation.setDuration(1000); // run animation for 1000 milliseconds or 1 second
rotateAnimation.setStartDelay(1000); // delay animation for 1000 milliseconds or 1 second

最后,为了在动画 运行 期间获得旋转角度,有一个名为 addUpdateListener 的侦听器方法:

rotateAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  @Override
  public void onAnimationUpdate(ValueAnimator animation) {
    int value = (int) animation.getAnimatedValue(); // dynamic value of angle
  }
});