java 启用屏幕旋转android

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10754614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 02:24:08  来源:igfitidea点击:

enable screen rotation android

javaandroidrotationorientation

提问by Paulius Vindzigelskis

I have disabled screen rotation in one activity in particular time. Now I need that particular time it will be enabled. How can I enable rotation, when i disabled it using this:?

我在特定时间禁用了一项活动中的屏幕旋转。现在我需要在特定时间启用它。当我使用以下方法禁用它时,如何启用旋转

回答by user219882

You can use this

你可以用这个

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);

See the official documentationfor more details

更多详情请查看官方文档

回答by kyogs

put this line in manifest

将此行放在清单中

android:configChanges="orientation"

and use this code as per your requirement

并根据您的要求使用此代码

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

and also put this to enable

并把它启用

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNDEFINED);

回答by limlim

Check out also that you don't have this line in your manifest file for your activity:

还要检查您的清单文件中是否没有此行用于您的活动:

android:screenOrientation="portrait"

That will disable the rotate of the screen.

这将禁用屏幕的旋转。

回答by adgllorente

This setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNDEFINED);is incorrect

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNDEFINED);不正确的

If you want to enable rotation again you have to use:

如果要再次启用旋转,则必须使用:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);

回答by Rafael T

If you want to enable rotation again, simply use:

如果您想再次启用旋转,只需使用:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNDEFINED);