Android provides three qualifiers that allow you to test for the dimensions of the device. Table 17.1 shows these new qualifiers.
Table 17.1 Discrete screen dimension qualifiers
Qualifier format | Description |
---|---|
wXXXdp
|
available width: width greater than or equal to XXX dp |
hXXXdp
|
available height: height greater than or equal to XXX dp |
swXXXdp
|
smallest width: width or height (whichever is smaller) greater than or equal to XXX dp |
Let’s say that you wanted to specify a layout that would only be used if the display were at least 300dp wide. In that case, you could use an available width qualifier and put your layout file in res/layout-w300dp (the “w” is for “width”). You can do the same thing for height by using an “h” (for “height”).
However, the height and width may swap depending on the orientation of the device. To detect a particular size of screen, you can use sw
, which stands for smallest width. This specifies the smallest dimension of your screen. Depending on the device’s orientation, this can be either width or height.
If the screen is 1024x800, then sw
is 800. If the screen is 800x1024, sw
is still 800.
3.230.1.23