首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RotateAnimation获取图像的电流角

RotateAnimation获取图像的电流角
EN

Stack Overflow用户
提问于 2019-09-19 09:01:12
回答 1查看 559关注 0票数 0

我有一个关于RotationAnimation的问题。

第一。

动画期间有听众吗?

启动,启动动画

重复,重复动画

停止,停止动画。

但是没有动画监听器来检查正在进行的操作。

第二,

还有其他的图像旋转角度吗?

我认为,ImageView是由rotationAnimation函数旋转的。

所以我做了一个计时线程并运行了1秒

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

'''

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

如何在旋转时得到当前的角度?

谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-19 09:35:29

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

代码语言:javascript
复制
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) {

  }
});

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

代码语言:javascript
复制
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都为您提供了时间控制:

代码语言:javascript
复制
rotateAnimation.setDuration(1000); // run animation for 1000 milliseconds or 1 second
rotateAnimation.setStartDelay(1000); // delay animation for 1000 milliseconds or 1 second

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

代码语言:javascript
复制
rotateAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  @Override
  public void onAnimationUpdate(ValueAnimator animation) {
    int value = (int) animation.getAnimatedValue(); // dynamic value of angle
  }
});

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58007384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档