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

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

本文介绍了强制android屏幕方向取决于屏幕大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,允许用户选择屏幕上的各种内容.在10英寸大屏幕上,这在横向上看起来最好,所以我将横向放在清单文件中.

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.

但是,我也希望使该应用程序对8(或7)英寸平板电脑的用户也友好.在这些屏幕尺寸下,应将应用程序强制设置为纵向模式.

However, I want to make the application friendly for users of 8 (or 7) inch tablets as well. 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?

推荐答案

要了解设备是7英寸,8英寸还是10英寸的平板电脑,您可以检查.

To find out if the device is a 7, 8 or 10 inches tablet, you can check this.

一种操作设备方向的方法是在每个活动中,在onCreate()之后,如下所示:

One way you can manipulate the device orientation is in every activity, after onCreate(), like this:

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

这篇关于强制android屏幕方向取决于屏幕大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 21:32