Android 仅限旋转横向

发布于 2024-12-23 03:24:53 字数 235 浏览 4 评论 0原文

我正在为 Android 平板电脑编写一个应用程序。我希望 ScreenOrientation 始终处于“横向”状态,但应用程序应该能够旋转 180°。如果将平板电脑倒置,视图应正确显示并旋转 180°。

有没有一种简单的方法可以做到这一点?目前,我仅在我为 Activity 编写的 android:screenOrientation="landscape" 清单中强制应用程序处于横向模式。但轮换不会那样进行。

I'm writing an application for an Android Tablet. I want the ScreenOrientation always to be in "Landscape", but the app should be able to rotate 180°. If you hold the Tablet upside down, the View should be displayed correctly and rotate 180°.

Is there a simple way to do this? At the moment I'm forcing the app to be in landscape mode only within the Manifest I wrote android:screenOrientation="landscape" for the activity. But the rotation won't work like that.

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

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

发布评论

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

评论(2

伴随着你 2024-12-30 03:24:53

请改用 android:screenOrientation="sensorLandscape"

横向,但根据设备传感器可以是正常或反向横向。添加到 API 级别 9。

请参阅开发指南

请注意如果您在 Activity 标记中使用 android:configChanges="orientation" 来避免屏幕旋转,则屏幕根本不会旋转。如果您希望它仅横向旋转,请使用上述选项并删除方向标志。在使用或不使用此选项之前检查您想要什么行为。

Use android:screenOrientation="sensorLandscape" instead.

Landscape orientation, but can be either normal or reverse landscape based on the device sensor. Added in API level 9.

See Dev Guide

Note that if you use android:configChanges="orientation" to avoid screen rotation in the activity tag, the screen will not rotate at all. If you want it to rotate only in landscape, use the option described above and remove the orientation flag. Check what is the behaviour you want before using this option or not.

昇り龍 2024-12-30 03:24:53

您需要实现一个方向传感器来检测手机的方向。看看下面的教程。当方向更改为 180 时,您需要设置视图

http://blog.androgames.net/ 135/android-orientation-tutorial/

You need to implement an orientation sensor that is used to detect the orientation of the phone. Have a look on the following tutorial. You need to set view when orientation changes to 180

http://blog.androgames.net/135/android-orientation-tutorial/

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