首页 > 解决方案 > 旋转动画功能,

问题描述

我被问到如何在旋转动画中获得旋转角度。

RotateAnimation 获取图像的当前角度

我的最终目标是根据运行轮盘赌设定的角度向微控制器发送信号。

我使用以下代码检查了旋转图像角度的日志:

objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {

                    double angle  = Double.parseDouble(objectAnimator.getAnimatedValue().toString());

                    Log.d("LOG", "animation : " + 

                }
                catch (Exception e){

                }

            }
        });

//setDuration -> 360
//range -> 0~360
//setInterpolator -> LinearInterpolator

日志如下所示。

D/LOG: animation : 0.0
D/LOG: animation : 0.0
D/LOG: animation : 33.0
D/LOG: animation : 49.0
D/LOG: animation : 66.0
D/LOG: animation : 83.0
D/LOG: animation : 99.0
D/LOG: animation : 133.0
D/LOG: animation : 150.0
D/LOG: animation : 166.0
D/LOG: animation : 183.0
D/LOG: animation : 216.00002
D/LOG: animation : 233.0
D/LOG: animation : 249.99998
D/LOG: animation : 266.0
D/LOG: animation : 283.0
D/LOG: animation : 316.0
D/LOG: animation : 333.0
D/LOG: animation : 350.0
D/LOG: animation : 360.0

我没有使用 LinearInterpolator 设置对图像旋转进行任​​何加速或减速。

我发现动画帧速率调用了onAnimationUpdate。(一定不?)

我想知道绝对角度,而不是动画更新时的角度。

我能怎么做?

还有其他方法可以制作旋转动画并获得绝对角度吗?

谢谢

标签: androidanimationobjectanimator

解决方案


推荐阅读