Android 仅限旋转横向
我正在为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请改用
android:screenOrientation="sensorLandscape"
。请参阅开发指南
请注意如果您在 Activity 标记中使用
android:configChanges="orientation"
来避免屏幕旋转,则屏幕根本不会旋转。如果您希望它仅横向旋转,请使用上述选项并删除方向标志。在使用或不使用此选项之前检查您想要什么行为。Use
android:screenOrientation="sensorLandscape"
instead.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.您需要实现一个方向传感器来检测手机的方向。看看下面的教程。当方向更改为 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/