[英]How to check when the phone changues from portrait to landscape? (with portrait mode forced in manifest)
I have a special need for my app. 我对我的应用有特殊需要。 I must force the app to work only in portrait mode, but i need to know when the user has moved the phone to landscape mode.
我必须强制该应用程序仅在纵向模式下工作,但是我需要知道用户何时将手机移至横向模式。 Why?
为什么? because i am displaying a opengl view with a texture image, and when the user changues the phone position to landscape mode i must rotate the polygon without reseting the activity.
因为我正在显示带有纹理图像的opengl视图,并且当用户将手机位置更改为横向模式时,我必须旋转多边形而不重置活动。 Then i must force portrait mode on manifest, because i dont want that my onCreate method gets called again.
然后,我必须在清单上强制使用肖像模式,因为我不希望再次调用我的onCreate方法。
Please, can someone tell me how to achieve this? 拜托,有人可以告诉我如何实现这一目标吗?
I know how to rotate the image, i only need to know when the user has moved the phone to landscape position, but with portrait forced on manifest. 我知道如何旋转图像,我只需要知道用户何时将手机移动到横向位置,但必须将肖像强制显示在清单上。
Thanks 谢谢
By "forced portrait", I assume you mean adding android:screenOrientation="portrait"
in the manifest. 通过“强迫肖像”,我假设您的意思是在清单中添加
android:screenOrientation="portrait"
。 All you need to do to know when orientation has changed is to also add android:configChanges="keyboardHidden|orientation"
to the <activity>
declaration in the manifest; 您只需要在清单中的
<activity>
声明中添加android:configChanges="keyboardHidden|orientation"
即可。 and then override onConfigurationChanged()
in your Activity
. 然后在
Activity
覆盖onConfigurationChanged()
。
Isn't this what you need? 这不是您所需要的吗? Doesn't this work?
这不行吗?
Read the following posts; 阅读以下文章; If you set it to sensor and then check in your activity what orientation the phone is in you can take actions accordingly.
如果将其设置为传感器,然后检查您的活动电话处于什么方向,则可以采取相应的措施。
Force orientation Force "portrait" orientation mode 强制方向强制“人像”定向模式
Then read this, specially the first answer with android:screenOrientation="sensor" Force an Android activity to always use landscape mode 然后阅读此内容,特别是使用android:screenOrientation =“ sensor”的第一个答案强制Android活动始终使用横向模式
http://developer.android.com/reference/android/content/res/Configuration.html#orientation http://developer.android.com/reference/android/content/res/Configuration.html#orientation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.