简体   繁体   English

如何查看手机从纵向变为横向的时间? (在清单中强制使用纵向模式)

[英]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.

相关问题 屏幕方向被强制设置为纵向,但倾斜时活动仍将旋转为横向! 如何强制人像模式? - Screen orientation forced to portrait, but still, the activities will rotate to landscape when tilted!! How to force portrait mode? 是否可以知道何时更改了屏幕方向,但在清单上强加了肖像模式? - It is possible to known when the screen orientation is changed but with portrait mode forced on manifest? 当Ativity不自动旋转时,如何检查手机的状态是横向还是纵向? - How check status of Phone is Landscape or Portrait when Ativity not auto rotation? Android:即使手机处于纵向模式,如何在横向模式下显示片段? - Android: How to display fragment in landscape mode, even if the phone is in portrait mode? 从肖像模式到风景模式问题 - From Portrait to Landscape mode issue 握住风景时如何显示人像模式以及握住风景时如何显示风景 - How to show portrait mode when holding in landscape and landscape when holding in portrait 如何检查照片是在Android的横向还是纵向模式下拍摄的? - How to check whether the photo was taken in landscape or portrait mode in Android? 加载了横向布局文件,而强制了纵向模式。 (机器人) - Landscape layout file is loaded, while portrait mode is forced. (Android) 将布局从纵向模式切换为横向模式时出现问题 - Problem when switching layouts from portrait to landscape mode 当方向从纵向更改为横向模式时出现意外行为 - unexpected behaviour when orientation changes from portrait to landscape mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM