我已经做了一些按钮使用setRotation()相应地旋转到设备方向。但是,我注意到这种变化并不顺畅,我想知道是否有一种简单的方法可以用RotateAnimation替换这种方法。主要问题是这些方向变化不会从相同的角度出现,例如,动画必须处理从0-90和270-90的旋转。我正在使用OrientationEventListener来检测角度方向。有任何想法吗?有没有办法让setRotation动画,还是用RotateAnimation替代它?
UPDATE:
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();
}
}
'ViewPropertyAnimator'? – tachyonflux