RotateAnimation获取当前图像角度 [英] RotateAnimation Get Current angle of image

查看:105
本文介绍了RotateAnimation获取当前图像角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RotationAnimation问题。

I have a question of RotationAnimation.

首先。

动画期间是否有监听器?

开始,开始动画

重复,重复动画

停止,停止动画。

First.
Is there a Listener to during animation?
start, start animation
repeat, repeat animation
stop, stop animation.

,但是没有动画侦听器可以检查运行情况。

but there are no animation listener to check the on going.

秒,

还有其他获得当前图像旋转角度的图像吗?

second,
is any other get a current rotate angle of image?

我认为ImageView是通过rotationAnimation函数旋转的。

,所以我制作了一个计时器线程并运行了1秒

I think, ImageView is rotate by rotationAnimation function.
so I made a timer thread and run 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);

'''

但是我看不到轮换期间的更改值。

but, I can't see the changed value during rotate.

如何在旋转过程中获得当前角度?

how can I get the current angle during rotate?

谢谢。

推荐答案

对于旋转动画,是,如下所示:

For Rotation Animation, Yes There is as shown below:

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

  }
});

您也可以使用对象动画师为旋转设置动画:

You can also use Object Animators to animate Rotation:

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 当前旋转角度的值。

To get the angle of your ImageView simply use imageView.getRotation(); this will give you an int value of the current angle of rotation.

您也不需要 Timer ,因为ObjectAnimator和rotationAnimator都可以为您提供时间控制:

You also don't need Timer because both ObjectAnimator and rotateAnimator provide time control for you:

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

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

Finally, To get rotation Angle DURING the time animation is running there is a listener method called addUpdateListener :

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

这篇关于RotateAnimation获取当前图像角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆