简体   繁体   中英

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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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