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
enable screen rotation android
提问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);