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

发布于 2025-01-07 23:30:35 字数 254 浏览 4 评论 0原文

我对我的应用程序有特殊需求。我必须强制应用程序仅在纵向模式下工作,但我需要知道用户何时将手机移至横向模式。为什么?因为我正在显示带有纹理图像的 opengl 视图,并且当用户将手机位置更改为横向模式时,我必须旋转多边形而不重置活动。然后我必须在清单上强制使用纵向模式,因为我不希望再次调用我的 onCreate 方法。

请问,有人可以告诉我如何实现这一目标吗?

我知道如何旋转图像,我只需要知道用户何时将手机移动到横向位置,但强制显示纵向。

谢谢

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. Then i must force portrait mode on manifest, because i dont want that my onCreate method gets called again.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟燃烟灭 2025-01-14 23:30:35

我认为“强制纵向”是指在清单中添加 android:screenOrientation="portrait" 。要知道方向何时更改,您需要做的就是将 android:configChanges="keyboardHidden|orientation" 添加到清单中的 声明中;然后在您的 Activity 中重写 onConfigurationChanged()

这不是你需要的吗?这行不通吗?

By "forced portrait", I assume you mean adding android:screenOrientation="portrait" in the manifest. 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; and then override onConfigurationChanged() in your Activity.

Isn't this what you need? Doesn't this work?

凉城凉梦凉人心 2025-01-14 23:30:35

阅读以下帖子;
如果您将其设置为传感器,然后检查您的活动,手机处于什么方向,您就可以采取相应的操作。

力方向
强制“纵向”方向模式

然后阅读此内容,特别是第一个答案 android:screenOrientation="传感器”
强制 Android Activity 始终使用横向模式

< a href="http://developer.android.com/reference/android/content/res/Configuration.html#orientation" rel="nofollow noreferrer">http://developer.android.com/reference/android/content/res/Configuration.html#orientation

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

http://developer.android.com/reference/android/content/res/Configuration.html#orientation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文