如何在支持自然横向设备的情况下检测横向左侧(正常)与横向右侧(反向)? [英] How to detect landscape left (normal) vs landscape right (reverse) with support for naturally landscape devices?

查看:24
本文介绍了如何在支持自然横向设备的情况下检测横向左侧(正常)与横向右侧(反向)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的事:

  • 检测设备的当前布局方向(纵向、横向-左、纵向(倒置)、横向-右)
  • 区分两种可能的横向模式(靠左、靠右)
  • 支持自然状态为横向的设备(例如在这里讨论过)
  • 支持
  • 2.2(不能使用getRotation())

澄清一下,我想知道布局当前的方向.布局的底部是哪个方向?是纵向的吗?是横向的吗?风景是左还是右?等等

Just to clarify, I want to know what orientation the layout is currently in. Which direction is the bottom of the layout? Is it in portrait? Is it in landscape? Is the landscape left or right? etc.

我能找到的最接近的是 Activity.getResources().getConfiguration().orientation,但它只返回三个可能的值.ORIENTATION_LANDSCAPE、ORIENTATION_PORTRAIT 或 ORIENTATION_SQUARE.它没有说明是哪种景观.

The closest I can find is Activity.getResources().getConfiguration().orientation, but it only returns three possible values. ORIENTATION_LANDSCAPE, ORIENTATION_PORTRAIT, or ORIENTATION_SQUARE. It does not say which type of landscape.

所以,然后我想,如果我能获得设备的方向值(如 90、180、270 等)并将其与上述配置值进行比较,我就能弄清楚.例如,如果配置值为 ORIENTATION_LANDSCAPE,方向为 270,我可以判断它处于反向横向模式.但是,似乎没有一种简单的方法来获取方向值.我可以实现一个 OrientationEventListener,但这似乎有点矫枉过正,因为我只需要在特定时间获取一次值,而不是一直获取.

So, then I thought, well if I can get the orientation value (like 90, 180, 270, etc) of the device and compare it to the above config value I could figure it out. For example, if the config value was ORIENTATION_LANDSCAPE and the orientation was 270, I could tell that it was in the reverse landscape mode. However, there doesn't appear to be an easy way to get the orientation value. I could implement an OrientationEventListener, but that seems overkill since I just need to get the value once at a specific time, not constantly.

Display 类中有两个值,但 getOrientation 已弃用,而 getRotation 是仅适用于 2.2 及更高版本.

There are two values in the Display class but getOrientation is deprecated and getRotation is only available for 2.2 and above.

现在,即使我确实得到了这个值,仍然存在自然横向设备的问题.这意味着它们的 0 值将是横向而不是纵向.所以我还需要一个确定的方法来判断哪个(横向左、横向或纵向)对应于 0.

Now, even if I did get this value, there is still the issue of devices that are naturally landscape. Meaning their 0 value would be landscape instead of portrait. So I also need a sure way to tell which (landscape-left, landscape-right or portrait) corresponds to 0.

在 SO 上有很多关于方向和类似问题的帖子,但我还没有看到任何将所有这些问题都考虑在内的帖子.有人知道吗?

There are a lot of posts on SO about orientation and similar issues, but I haven't seen any that take all of these issues into consideration. Has anyone figured this out?

当一切都说完了,我想要像 Activity.getResources().getConfiguration().orientation 这样的东西,但能够分辨出它是哪种横向模式.

When all is said and done I would like something like Activity.getResources().getConfiguration().orientation but be able to tell which landscape mode it is.

推荐答案

直到 2.2 才支持右横向.您需要在选项中选择 <2.2 设备.

Right landscape wasn't supported till 2.2. You'll need to have <2.2 devices choose in the options or something.

这篇关于如何在支持自然横向设备的情况下检测横向左侧(正常)与横向右侧(反向)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆