Confusion with "smallest width 600 dp" selector

Mukesh Bhojwani picture Mukesh Bhojwani · Apr 19, 2013 · Viewed 11.7k times · Source

In my application I am supporting phone/tablet form factors and to have individual layouts I use selector "layout" (for phones), "layout-sw600dp" (for tablets).

Following are the details:

http://android-developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html

Typical numbers for screen width dp are:
320: a phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
480: a tweener tablet like the Streak (480x800 mdpi).
600: a 7” tablet (600x1024).
720: a 10” tablet (720x1280, 800x1280, etc).

I am having a Nexus 4 mobile, following are its attirbutes

Size:       4.7 inches
Resolution: 768 x 1280 pixels
DPI:        318
dp:         386 
Here is the dp calculation
dp = (px * 160)/dpi
dp = (768 * 160)/318

When I use 768 px in dp calculation formula the dp value comes as 386, but when I pass 1280 px the dp value comes as 644.

With the following understanding I thought for Nexus 4 landscape it would read the layout from sw600dp, but that's not the case.

As the resolution is width X Height, it will be reversed when the device is rotated.

I thought this is the improvisation made with sw selectors compare to pre-3.2 large, xlarge sectors.

Answer

SK9 picture SK9 · Jun 26, 2013

As it says in the Android documentation here in bold (scroll down a bit to the "smallestWidth" section of Table 2):

The smallestWidth is a fixed screen size characteristic of the device; the device's smallestWidth does not change when the screen's orientation changes.