我希望我的屏幕之一是严格横向的,但是,当设备翻转(倒置)但仍处于横向模式时,我希望我的活动也颠倒
我怎么做?
试试 android:screenOrientation="sensorLandscape"
在您的活动中,您必须覆盖 ConfigurationChange 并使其保持横向。
例如:
@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
只需在清单中的活动标签中设置 android:screenOrientation="landscape" 即可。这将迫使它景观化。
这就是我想要的:
OrientationEventListener orientationEventListener = new OrientationEventListener(this,Consts.SENSOR_ORIENTATION_DELAY_MS) {
@Override
public void onOrientationChanged(int orientation) {
Log.d(TAG,"sensor");
if(orientation>Consts.THRESHOLD_FOR_ORIENTATION_CHANGE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
}else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
};
if(orientationEventListener.canDetectOrientation()) {
orientationEventListener.enable();
}