如何检查设备自然(默认)方向上的Andr​​oid(即获得景观的如摩托罗拉Charm或FLIPOUT)摩托罗拉、景观、自然、设备

2023-09-11 20:32:44 作者:笑到全世界都流泪

我已经显示了从摄像头preVIEW一个活动,所以需要将只设置景观。在底部(不考虑设备旋转的)我想显示一个文本视图。我使用OrientationEventListener赋予其天然位置设备的方向。我可以实现一个解决方案,在肖像默认设备运行良好,但使它也可以用在我需要知道这种设备上运行的景观默认设备。因此,问题是如何检查呢?

I have an activity showing preview from camera, so it need to be set as landscape only. At the bottom (regardless of device rotation) I want to show a text view. I am using OrientationEventListener which gives device's orientation from its natural position. I can implement a solution which works well on portrait default devices but to make it work also on landscape default devices I need to be aware of running on such a device. Thus the question is how to check it?

推荐答案

这是可以做到使用的 Display.getOrientation()或的 Display.getRotation()(对于API级别> = 8)。

It can be done using Display.getOrientation() or Display.getRotation() (for API level >= 8).