我目前正在开发一个应用程序,希望用箭头(类似指南针)来指示路径。
为了将箭头移动到正确的方向,我使用了RotateAnimation
类。它的效果非常好,但是当初始角度位置与最终角度位置相差很大时,旋转不会选择更快的方式。
在这个视频中,你可以看到这种行为:https://youtu.be/vypZni_1s3I
以下是用户点击“02”按钮时执行的代码:
RotateAnimation rotateAnimation = new RotateAnimation(355f, 8f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration(3000);
rotateAnimation.setFillAfter(true);
test.startAnimation(rotateAnimation);
当用户点击“03”按钮时执行的代码如下:
RotateAnimation rotateAnimation = new RotateAnimation(8f, 350f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration(3000);
rotateAnimation.setFillAfter(true);
test.startAnimation(rotateAnimation);
如您在视频中所见,旋转并没有选择更快的方式。在第一个动画中,更快的方式是顺时针旋转(但系统选择了逆时针旋转),在第二个动画中,更快的方式是逆时针旋转(但系统选择了顺时针旋转)。
是否有解决方案或技巧可以强制系统选择更快的方式以从点A旋转到点B?