如何使用code,以确定设备的屏幕尺寸类别(小,中,大,XLARGE)?如何使用、类别、设备、屏幕尺寸

2023-09-11 11:47:31 作者:墨染雪殇#

有什么方法来确定当前的设备,如小,正常,大,XLARGE的屏幕尺寸的范畴?

Is there any way to determine the category of screen size of the current device, such as small, normal, large, xlarge?

不是密度,但屏幕尺寸。

Not the density, but the screen size.

推荐答案

您可以使用Configuration.screenLayout位掩码。

You can use the Configuration.screenLayout bitmask.

例如:

if ((getResources().getConfiguration().screenLayout & 
    Configuration.SCREENLAYOUT_SIZE_MASK) == 
        Configuration.SCREENLAYOUT_SIZE_LARGE) {
    // on a large screen device ...

}