简体   繁体   English

强制android屏幕方向取决于屏幕大小

[英]Force android screen Orientation depending on screen size

I am writing an application that allows users to select various things on the screen. 我正在编写一个应用程序,允许用户选择屏幕上的各种内容。 On large 10 inch screens this looks best in landscape so I force landscape in the manifest file. 在10英寸大屏幕上,这在横向上看起来最好,因此我将横向放在清单文件中。

However, I want to make the application friendly for users of 8 (or 7) inch tablets as well. 但是,我也想使该应用程序对8(或7)英寸平板电脑的用户友好。 On these screen sizes the application should be forced in portrait mode. 在这些屏幕尺寸下,应将应用程序强制设置为纵向模式。

Does anyone know how I can force the screen orientation depending on the screen size? 有谁知道我如何根据屏幕尺寸来强制屏幕方向?

To find out if the device is a 7, 8 or 10 inches tablet, you can check this . 要了解该设备是7英寸,8英寸还是10英寸的平板电脑,可以选中此项

One way you can manipulate the device orientation is in every activity, after onCreate(), like this: 操纵设备方向的一种方法是在onCreate()之后的每个活动中进行如下操作:

    // set the orientation of the device
    if(isTabletWith10Inches) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

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

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