我已經做了一些按鈕使用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