android:screenOrientation="portrait" 在 Jellybean 中被忽略。如果我将手机变成横向,无论如何它都会改变方向。我试过几部手机。我必须使用任何新标志吗?
问问题
1877 次
1 回答
2
您可以尝试以编程方式进行,
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
switch (newConfig.orientation)
{
case Configuration.ORIENTATION_PORTRAIT:
// taking action on event
lockScreenRotation(Configuration.ORIENTATION_PORTRAIT);
break;
case Configuration.ORIENTATION_LANDSCAPE:
// taking action on event
lockScreenRotation(Configuration.ORIENTATION_LANDSCAPE);
break;
case Configuration.ORIENTATION_SQUARE:
// taking action on event
lockScreenRotation(Configuration.ORIENTATION_SQUARE);
break;
default:
throw new Exception("Unexpected orientation!!!");
break;
}
private void lockScreenRotation(int orientation)
{
// Stop the screen orientation changing during an event
switch (orientation)
{
...
case Configuration.ORIENTATION_PORTRAIT:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
case Configuration.ORIENTATION_LANDSCAPE:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
...
case default:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
break;
}
}
于 2012-12-12T16:55:45.647 回答