如何得到它?在我的XML文件中,我为我的活动使用唯一的纵向方向。如何在不使用加速度计的情况下获取屏幕方向?
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden"
and onConfigurationChanged并且不适用于方向。
UPD目前我使用:
@Override
public void onSensorChanged(SensorEvent event) {
x = event.values[0];
y = event.values[1];
}
private PictureOrientation getLastOrientation() {
MyPictureOrientation orient;
if (x >= -5 && x < 5) {
if (y > 0) {
orient = PORTRAIT;
} else {
orient = PORTRAIT_REV;
}
} else {
if (x >= -10 && x < -5) {
orient = LAND_RIGHT;
} else {
orient = LAND_LEFT;
}
}
return orient;
}
getResources()getConfiguration()方向 - 永远== 1 – monyag