For the More Curious: More on Determining Device Size

Before Android 3.2, the screen size qualifier was used to provide alternative resources based the size of a device. Screen size is a qualifier that groups different devices into four broad categories – small, normal, large, and xlarge.

Table 17.1 shows the minimum screen sizes for each qualifier.

Table 17.1  Screen size qualifiers

Name Minimum screen size
small 320x426dp
normal 320x470dp
large 480x640dp
xlarge 720x960dp

Screen size qualifiers were deprecated in Android 3.2 in favor of qualifiers that allow you to test for the dimensions of the device. Table 17.2 shows these new qualifiers.

Table 17.2  Discrete screen dimension qualifiers

Qualifier format Description
wXXXdp available width: width is 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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.221.163