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

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

问题描述

我想这样做的:

  • 检测设备的当前布局的方向(纵向,横向左,纵向(上下颠倒),风景右)
  • 的两种可能的横向模式(靠在左侧,靠在右侧)
  • 之间的区分 有景观为自然状态
  • 支持设备(<一href="http://www.motorola.com/Consumers/US-EN/Consumer-Product-and-Services/Mobile-Phones/MOTOROLA-CHARM-with-MOTOBLUR-US-EN">for例如,<一个href="http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html">discussed这里)
  • 支持&LT; 2.2(不能用<一个href="http://developer.android.com/reference/android/view/Display.html#getRotation%28%29">getRotation())
  • Detect the current layout orientation of the device (Portrait, Landscape-Left, Portrait(upside down), Landscape-Right)
  • Differentiate between the two possible landscape modes (leaning on the left side, leaning on the right side)
  • Support devices that have landscape as their natural state (for example, discussed here)
  • Support < 2.2 (can't use 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.

最近我能找到的<一个href="http://developer.android.com/reference/android/content/res/Configuration.html#orientation">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,我可以告诉大家,这是在相反的横向模式。然而,似乎没有成为一个简单的方法来获取定位值。我可以实现的<一个href="http://developer.android.com/reference/android/view/OrientationEventListener.html">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.

有在显示类中的两个值,但<一个href="http://developer.android.com/reference/android/view/Display.html#getOrientation%28%29">getOrientation是德precated和<一href="http://developer.android.com/reference/android/view/Display.html#getRotation%28%29">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()。方向,但可以告诉它是横向模式。

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。 你需要有&LT; 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天全站免登陆