有没有办法为 setRotation 设置动画,还是应该用 RotateAnimation 代替?

Is there a way to animate setRotation or should it be replaced with a RotateAnimation?

我使用 setRotation() 使一些按钮根据设备方向旋转。但是,我注意到这种变化并没有顺利发生,我想知道是否有一种简单的方法可以用 RotateAnimation 替换这种方法。主要问题是这些方向变化不会从相同的角度发生,例如动画必须处理 0-90 和 270-90 的旋转。我正在使用 OrientationEventListener 来检测角度方向。有什么想法吗?

更新:

   OrientationEventListener orientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_UI) {

    @Override 
    public void onOrientationChanged(int angle) {
        float currentAngle = downloadStatus.getRotation();
        if(angle > 260 && angle < 280) {
            downloadStatus.animate().rotationBy(90 - currentAngle).setDuration(100).start();
        } else if(angle > 80 && angle < 100) {
            downloadStatus.animate().rotationBy(-90 - currentAngle).setDuration(100).start();
        } else if(angle > 350 || angle < 10){
            downloadStatus.animate().rotationBy(-currentAngle).setDuration(100).start();
        } else if(angle > 170 && angle < 190){
            downloadStatus.animate().rotationBy(180 - currentAngle).setDuration(100).start();
        } 
    } 
}; 
orientationEventListener.enable();

我接下来尝试用以下两个替换反向纵向角度:

while (MyButtonCurrentAngle==90) { 
    if (ButtonsAngle > 170 && ButtonsAngle < 190) {
        MyButton.animate().rotationBy(90 - MyButtonCurrentAngle).setDuration(100).start();
    }
}
while (MyButtonCurrentAngle==270) { 
    if (ButtonsAngle > 170 && ButtonsAngle < 190) {
        MyButton.animate().rotationBy(-90 - MyButtonCurrentAngle).setDuration(100).start();
    }
}

尝试将我以前的代码更新为:

    OrientationEventListener orientationEventListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_UI) {

        @Override
        public void onOrientationChanged(int angle) {
            float currentAngle = downloadStatus.getRotation();
            if(angle > 260 && angle < 280) {
                downloadStatus.animate().rotationBy(90 - currentAngle).setDuration(100).start();
            } else if(angle > 80 && angle < 100) {
                downloadStatus.animate().rotationBy(-90 - currentAngle).setDuration(100).start();
            } else if(angle > 350 || angle < 10){
                downloadStatus.animate().rotationBy(-currentAngle).setDuration(100).start();
            }
        }
    };
    orientationEventListener.enable();