For the More Curious: More on Determining Device Size

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 ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.