Supporting 3 different screen sizes using available screen width qualifier w<N>dp

1.7k Views Asked by At

The layout automatic switch works just fine for 2 layouts for my 2 devices but not the third.

I have 2 Android phones (my assumption is that ppi is the same as dpi here)

  • HTC Desire - (480x800; 252 dpi; Android 2.2)
  • HTC Sensation - the longer side is >600dp (540x960 pixels; 256 dpi; Android 4.0.4)
  • Sony Xperia Z - the longer side is >690dp (1080x1920 pixels; 443 dpi; Android 4.2.2)

So, I created the following layouts to take care of the 3 phones' screens (I'm not using smallest available width sw<N>dp qualifier because my app only support landscape view; therefore, I only care about the longer size of the screen)

/res/layout/main.xml
/res/layout-w600dp/main.xml
/res/layout-w690dp/main.xml

The /res/layout/main.xml layout shows up correctly for the HTC Desire and /res/layout-w600dp/main.xml for HTC Sensation but not the Xperia Z (/res/layout/main.xml shows up instead of /res/layout-w690dp/main.xml)

Did I miss something?

My app is targeting Android 4.0 (so I'm only looking at the screen size qualifiers for Android 3.2 and above)

I thought of checking the screen size at run time and then choose the appropriate layout but then in that case the qualifiers would be used, wouldn't they?

My manifest.xml at the moment:

...
<uses-sdk android:minSdkVersion="8"
        android:targetSdkVersion="14" />
    <supports-screens
            android:smallScreens="true"
            android:normalScreens="true" 
            android:largeScreens="true"
            android:xlargeScreens= "true"
            android:anyDensity="true" />
...

Updates
Now that I've used DensityMetrics to discover the density of my phones' screen, they are not actually the same as the PPI figures:

  • HTC Sensation - 240dpi
  • Xperia Z - 480dpi

So both HTC Sensationa and Xperia Z has 360dp x 640dp size. I removed 1 layout and keep the following:

/res/layout/main.xml
/res/layout-w600dp/main.xml

When I run my app, the HTC Sensation still shows the /res/layout-w600dp/main.xml layout while the Xperia Z is still showing the /res/layout/main.xml.

What is going on?

1

There are 1 best solutions below

0
On

I used w500dp-land as screen size qualifier for landscape on the Xperia Z. That at least works whereas w600dp-land is ignored. After checking the device that makes sense: The Xperia Z dp dimensions are 360 * 592 according to https://play.google.com/store/apps/details?id=com.sturnus.screeninfo