Android device screen size determination

Before Android 3.2, screen size modifiers provided optional resources based on the device's screen size. The screen size modifier divides different devices into four categories: small, normal, large, and xlarge.

The table below shows the minimum screen size for each category modifier

name Minimum screen size
small 320*426dp
normal 320*470dp
large 480*640dp
xlarge 720 * 960dp

The screen size modifier has been deprecated in Android 3.2 in line with the introduction of a new modifier that allows developers to test device sizes. The following table lists the newly introduced modifiers.

Modifier format describe
wXXXdp Effective width: width greater than or equal to XXXdp
hXXXdp Valid Height: Height greater than or equal to XXXdp
swXXXdp min-width: width or height (the smallest of the two) is greater than or equal to XXXdp

Suppose you want to specify that a layout is only suitable for devices with a screen width of at least 300dp, you can use the width modifier and put the layout file in the res/layout-w300dp directory (w stands for screen width). Similarly, we can also use the "hXXXdp" modifier (h stands for screen height).

If the orientation of the device changes, the height and width of the device will also change. To determine a specific screen size, we can also use sw (minimum width). sw specifies the minimum specification size of the screen. The orientation of the device changes, so sw can be either a minimum width or a minimum height. For example, if the screen size is 1024*800, then the sw value is 800; and if the screen size is 800*1024, then the sw value is still 800.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325604473&siteId=291194637