如何检测横向向左(正常)与景观右(反向)与自然景观设备的支持?自然景观、横向、景观、正常

2023-09-06 08:19:04 作者:男人 我不稀罕你

我想这样做的:

检测设备的当前布局的方向(纵向,横向左,纵向(上下颠倒),风景右) 的两种可能的横向模式(靠在左侧,靠在右侧)之间的区分 有景观为自然状态支持设备(for例如,discussed这里) 支持&LT; 2.2(不能用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.

最近我能找到的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.

有在显示类中的两个值,但getOrientation是德precated和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.

 
精彩推荐
图片推荐