锁定/解锁方向
要将方向锁定为纵向,我使用:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
我不确定哪个标志告诉活动返回依赖设备方向。我想它是其中之一:
SCREEN_ORIENTATION_FULL_SENSOR
SCREEN_ORIENTATION_SENSOR
SCREEN_ORIENTATION_UNSPECIFIED
SCREEN_ORIENTATION_USER
另一方面,为什么 Android 文档不开源?文档完全缺乏。很少有函数和标志有有用的描述。
To lock my orientation to portrait, I use:
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
I'm unsure what flag tells the activity to go back to relying on the device orientation. I imagine it is one of these:
SCREEN_ORIENTATION_FULL_SENSOR
SCREEN_ORIENTATION_SENSOR
SCREEN_ORIENTATION_UNSPECIFIED
SCREEN_ORIENTATION_USER
On another note, why isn't the android documentation open source? The documentation is completely lacking. Very few of the functions and flags have useful descriptions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 http://developer.android.com/reference/android/R。 attr.html#screenOrientation(如果您仔细阅读文档,screenOrientation 就是这些值所链接的内容)、
SCREEN_ORIENTATION_SENSOR
或SCREEN_ORIENTATION_FULL_SENSOR
会做到这一点,具体取决于您想要多大的灵活性 - 但是,我怀疑您真正想要的是回到默认设置,即SCREEN_ORIENTATION_UNSPECIFIED
以便它会返回系统默认设置,包括用户设置的任何设置。Per http://developer.android.com/reference/android/R.attr.html#screenOrientation (screenOrientation being what those values are linked to if you dig through the documentation),
SCREEN_ORIENTATION_SENSOR
orSCREEN_ORIENTATION_FULL_SENSOR
will do it, depending on how much flexibility you want -- however, I suspect what you really want is to go back to the default setting, which isSCREEN_ORIENTATION_UNSPECIFIED
so that it goes back to the system defaults, including any the user set.对我来说,一个简单的修复方法是在 AndroidManifest.xml 中添加一行,如下所示:
Add android:screenOrientation="portrait">在应用程序部分。
An easy fix for this that worked for me is to add a line to AndroidManifest.xml like so:
Add android:screenOrientation="portrait"> in the application section.