[英]Switch screen to landscape or portrait but don't lock orientation
I would like to accomplish something like this: 我想完成这样的事情:
What would be the correct way to do this? 正确的方法是什么? I am trying to lock the screen with the following command:
我正在尝试使用以下命令锁定屏幕:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
And then immediately calling: 然后立即调用:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
The problem is that this immediately transfers screen back to portrait mode. 问题在于这会立即将屏幕转换回纵向模式。 Screen just blinks for a half a second.
屏幕仅闪烁半秒钟。
Use can use in java code: 使用可以在Java代码中使用:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requesting to turn the title OFF
requestWindowFeature(Window.FEATURE_NO_TITLE);
// making it full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
You can also do in AndroidManifest.xml: 您也可以在AndroidManifest.xml中执行以下操作:
<activity
android:name="com.example.main"
android:label="@string/app_name"
android:screenOrientation="landscape" >
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.