横向模式时不同设备上的不同屏幕方向
Different screen orientation on different devices when landscape mode
我正在使用
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
对于我的 Activity,我正在尝试使用 OrientationEventListener
来查找设备的方向。在某些设备上,我的横向显示值约为 270,而其他设备显示的值约为 0。在放置主页按钮的每个设备上,方向值显示 0。在横向模式下持有所有设备时,我希望具有相同的值。有没有一个标志可以告诉我哪个设备显示 270 或 0 作为默认方向的横向模式。
这是我的OrientationEventListener
mOrientationListener = new OrientationEventListener(this,
SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int orientation) {
Log.v("Orientation changed to ", String.valueOf(orientation));
}
};
有什么技巧可以帮助解决问题吗?
我找到了解决方法。
使用这段代码,我得到了默认的显示旋转:
int rotation = getWindowManager().getDefaultDisplay().getRotation();
在我的 onOrientationChanged
方法的主体中,我可以这样做:
if (rotation == 0) {
if (orientation >= 90 && orientation <= 270) {
}
} else if (rotation == 1) {
if (orientation < 180 && orientation > 0 ) {
}
}
只有当我的设备没有处于正确的横向位置时才会进入。如果我的设备处于 90+ 角度,我可以给用户一个消息。
我正在使用
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
对于我的 Activity,我正在尝试使用 OrientationEventListener
来查找设备的方向。在某些设备上,我的横向显示值约为 270,而其他设备显示的值约为 0。在放置主页按钮的每个设备上,方向值显示 0。在横向模式下持有所有设备时,我希望具有相同的值。有没有一个标志可以告诉我哪个设备显示 270 或 0 作为默认方向的横向模式。
这是我的OrientationEventListener
mOrientationListener = new OrientationEventListener(this,
SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int orientation) {
Log.v("Orientation changed to ", String.valueOf(orientation));
}
};
有什么技巧可以帮助解决问题吗?
我找到了解决方法。
使用这段代码,我得到了默认的显示旋转:
int rotation = getWindowManager().getDefaultDisplay().getRotation();
在我的 onOrientationChanged
方法的主体中,我可以这样做:
if (rotation == 0) {
if (orientation >= 90 && orientation <= 270) {
}
} else if (rotation == 1) {
if (orientation < 180 && orientation > 0 ) {
}
}
只有当我的设备没有处于正确的横向位置时才会进入。如果我的设备处于 90+ 角度,我可以给用户一个消息。