[英]android:screenOrientation=”locked” on old OS versions
Even if device is rotated, I want my activity to maintain the orientation it was started in, whether it was portrait or landscape. 即使旋转设备,我也希望我的活动保持其开始时的方向,无论是纵向还是横向。 API level 18 introduced
android:screenOrientation=”locked”
that should do the job: Locks the orientation to its current rotation, whatever that is.
API级别18引入了
android:screenOrientation=”locked”
应该完成的工作: Locks the orientation to its current rotation, whatever that is.
However, I want to support also older OS versions. 但是,我也要支持较旧的OS版本。 How can I achieve this?
我该如何实现?
I'm aware of Lock screen orientation (Android) that discusses locking activity to landscape mode, How do I disable orientation change on Android? 我知道“ 锁定屏幕方向”(Android)讨论了将活动锁定为横向模式, 如何在Android上禁用方向更改? that discusses locking activity in portrait mode (that did not work for me at all on Samsung Galaxy S, OS 2.3.3).
讨论了锁定肖像模式下的活动(在Samsung Galaxy S,OS 2.3.3上根本不适合我)。 I'm also aware of advice recommending not to do this .
我也知道建议不要这样做的建议 。
MainActivity.java : MainActivity.java :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getResources().getConfiguration().orientation == Configuration. ORIENTATION_LANDSCAPE)
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
else
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// ...
}
I have also modified the manifest file. 我还修改了清单文件。 However, I'm not sure if these changes are needed, at least
android:screenOrientation="unspecified"
is the default screenOrientation value anyway. 但是,我不确定是否需要这些更改,至少
android:screenOrientation="unspecified"
仍然是默认的screenOrientation值。 AndroidManifest.xml : AndroidManifest.xml :
<activity android:name="MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="unspecified" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.