简体   繁体   English

如何确定主屏幕的方向

[英]How to determine orientation of home screen

Is there a way to determine programmatically the orientation of the home screen? 有没有办法以编程方式确定主屏幕的方向? I've toyed with the following: 我玩弄了以下内容:

WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
int rotation = windowManager.getDefaultDisplay().getRotation();

and

Resources r = context.getResources();
int orientation = r.getConfiguration().orientation;

But neither seems particularly suitable because, as I understand it, the home screen may well be locked in a particular orientation, even if the screen orientation is changing. 但是,这两种方法似乎都不适合,因为据我所知,即使屏幕方向发生变化,主屏幕也很可能锁定在特定的方向上。 Most notably, phone-like devices seem to be locked in portrait orientation, whereas tablet screens seem to have homescreens that rotate, though which perhaps can be locked too. 最值得注意的是,类似手机的设备似乎以纵向锁定,而平板电脑屏幕似乎具有可旋转的主屏幕,尽管也可以将其锁定。

Basically I need the information in order to update a home screen widget correctly (to determine its width and height using eg OPTION_APPWIDGET_MIN_WIDTH and OPTION_APPWIDGET_MAX_HEIGHT if in portrait). 基本上,我需要信息以便正确更新主屏幕小部件(如果是纵向,则使用OPTION_APPWIDGET_MIN_WIDTHOPTION_APPWIDGET_MAX_HEIGHT确定其宽度和高度)。 But if the screen happens to be in landscape while the widget is updating in the background, it is getting width and height the wrong way around because the home screen will actually be in portrait. 但是,如果在窗口小部件在后台更新时屏幕恰好是横向的,则显示宽度和高度的方向错误,因为主屏幕实际上是纵向的。

Any way to get the home screen orientation reliably? 有什么方法可以可靠地获得主屏幕方向吗?

Is there a way to determine programmatically the orientation of the home screen? 有没有办法以编程方式确定主屏幕的方向?

No. The author of the home screen can do whatever the author wants. 不可以。主屏幕的作者可以执行作者想要执行的任何操作。 For all you know, things are displayed on a diagonal. 众所周知,事物显示在对角线上。 And, since there are hundreds, perhaps thousands, of home screen implementations, the behavior on any given device will be indeterminate. 并且,由于有数百甚至数千个主屏幕实现,因此任何给定设备上的行为都是不确定的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM