Android 屏幕方向挑战
我想做一些关于屏幕方向的独特事情:
(1)当活动开始时,如果设备处于纵向方向,我想显示一个视图,要求用户将设备旋转到横向方向。
(2) 设备旋转后,我想显示一个新视图,其中包含活动的主 UI。
(3) 如果用户之后进一步旋转设备,我想保留在步骤 2 中选择的方向,或者仅允许反向横向方向,而不允许纵向方向。
到目前为止,我可以执行步骤 1 和 2,但我不知道如何完成步骤 3。我以为我可以将我请求的方向设置为横向或传感器横向,但这不起作用(在第一种情况,根据原始方向,我得到一个颠倒的屏幕,而在第二种情况下,由于某种原因,我总是得到纵向方向)。
有什么建议吗?谢谢。
I want to do something somewhat unique regarding screen orientation:
(1) When the activity starts, if the device is in Portrait orientation, I want to display a view that asks the user to please rotate the device into Landscape orientation.
(2) Once the device is rotated, I want to show a new view which contains the main UI for the activity.
(3) If the user rotates the device further afterward, I want to either retain the orientation selected in step 2 or allow only the reverse-landscape orientation, and disallow portrait orientation.
So far I'm able to do steps 1 and 2, but I can't figure out how to accomplish step 3. I thought I could set my requested orientation to either Landscape or Sensor Landscape, but that doesn't work (in the first case I get an upside-down screen depending on the original orientation and in the second I always get portrait orientation for some reason).
Any advice? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看如何在 Android 上禁用方向更改?
Take a look at How do I disable orientation change on Android?
或者锁定屏幕方向 (Android)
Or Lock screen orientation (Android)