5

When testing my application at WXGA720 resolution on the Android Emulator running 4.0.3 Ice Cream Sandwich, my app takes the layout assets from the layout-normal-land-854x480 folder in landscape view and the layout-port-480x320 folder for portrait view. I would like to be able to specifically target this resolution so my app displays properly on the new phones. How do I do this? I have tried the following...

layout-normal-land-xhdpi
layout-normal-port-xhdpi
layout-normal-land-xlarge
layout-normal-land-large
layout-normal-land-1280x720
layout-normal-port-1280x720, etc...

...and it still takes the assets from the wrong folders detailed above.

My app is targeting Android 2.1 (which I assume is still the standard target these days), so I can't as far as I know use the new layout qualifiers. Is this a bug? Has anyone had this same issue and found a workaround?

I have the following folder configuration, and all of the other AVDs display as expected:

layout
layout-land
layout-normal-land-480x320
layout-normal-land-854x480
layout-port-480x320
layout-port-800x480

Matt W
  • 686
  • 1
  • 9
  • 12
  • Same problem here, it does not take the resources from xhdpi folder. I declared the supports-screens tag with android:largeScreens="true" ... doesn't seem to help. xlargeScreens is supported from API 9, I'm developing for 7, maybe that's the problem? – User Jul 22 '12 at 18:44

3 Answers3

5

When testing my application at WGXA720 resolution on the Android Emulator running 4.0.3 Ice Cream Sandwich, my app takes the layout assets from the layout-normal-land-854x480 folder in landscape view and the layout-port-480x320 folder for portrait view.

If I had to guess, you do not have a valid <supports-screens> element (or possibly no android:minSdkVersion) in your manifest, and so you are being thrown into a compatibility mode.

Also, please don't use suffixes like -480x320 and -854x480. These were removed from the documentation for a reason. Whatever problem you think you are solving with them can be better solved some other way.

My app is targeting Android 2.1 (which I assume is still the standard target these days), so I can't as far as I know use the new layout qualifiers.

You can set your build target to a higher level and use the new layout qualifiers. However, older devices will ignore them, so you will still need to use -normal and -land and kin for them, in parallel with any resource sets with the new qualifiers. You can create resource aliases to minimize code duplication.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I appreciate the help, but I'm still completely stuck after working on this for the past several hours. I removed the pixel-specific suffixes and tried replacing them with just 'large' or 'hdpi', etc., and every AVD used the 'mdpi' folder, no matter what the screen density or resolution really was. Per the docs: "These minimum screen sizes were not as well defined prior to Android 3.0, so you may encounter some devices that are mis-classified between normal and large." Hence, the only way for me to define layouts correctly is to use the pixel-specific suffixes. – Matt W Jan 25 '12 at 20:15
  • I also tried adding the element to the manifest file, changing the build target to 13, and using the new layout qualifiers (sw720dp) - It ignores this and IT STILL WANTS TO USE THE SAME FOLDERS. The only way I've been able to effectively target this is to do it programatically, by obtaining the device width and changing the layout parameters via code - something I'm trying to avoid here. – Matt W Jan 25 '12 at 20:19
  • @MattW: Your development environment must be completely messed up. Stuff like `-large` and `-hdpi` work just fine for tens of thousands of other developers. I have no idea how to help you further. – CommonsWare Jan 25 '12 at 22:46
  • Same problem here, it does not take the resources from xhdpi folder. I declared the supports-screens tag with android:largeScreens="true" ... doesn't seem to help. xlargeScreens is supported from API 9, I'm developing for 7, maybe that's the problem? – User Jul 22 '12 at 18:44
  • 1
    @lxx: `-largeScreens` has absolutely nothing whatsoever to do with `-xhdpi`. – CommonsWare Jul 22 '12 at 18:45
1

I was having a similar problem displaying my layouts properly but I was using the HTC Rezound that has 1280 by 720 resolution. It uses Android version 2.3.4. My screens were only showing on the upper portion of the display and the bottom third was black. Everything was displaying properly using lower resolution phones.

I went through the exercise of making new layout directories ( layout-xhdpi, layout-large, layout-1280x720, layout-1200x700, etc) and modifying my layout files to match the larger resolution, but each attempt failed and the app always showed in the upper part of the screen only. I had read the docs from http://developer.android.com/guide/practices/screens_support.html and did not find anything that solved the problem. I finally fixed it, and the solution had nothing whatsoever to with adding new layout directories set up for higher resolutions! The solution was all about the "uses-sdk" statement in the AndroidManifest.xml file. My original manifest contained the statement:

<uses-sdk minSdkVersion="8"/>

With only the minimum sdk version specified, the graphics would not display properly on the Rezound. However, after changing only one line in the AndroidManifest.xml (and making no other changes) the phone displayed all the screens properly:

<uses-sdk android:targetSdkVersion="9" minSdkVersion="8" />

Why did this fix it but not the documented methods? I don't know! I am finding many hidden connections in Android that seem to defy a logical explanation. Can someone explain to me why changing the uses-sdk statement is critical to displaying on a higher resolution display?

Tary
  • 1,021
  • 1
  • 10
  • 13
  • I think the issue might be relying to Eclipse. Its too late now to determine it but I guess that Eclipse cleared cache and reassembled your project right after changing the targetSdkVersion cuz this means new code checks and thus recompile and so on. Ive noticed that while working with layouts Eclipse's "Project - Clean" often helps to get visible changes in graphics. – Stan May 07 '13 at 21:41
1

I had answered this question before but my previous response only allowed me to fill the display (it only filled the top third before) but I could never get an alternate layout to be used. I am using an HTC Rezound which has a 1280 by 720 display. I needed to find out what kind of display Android thinks that it is. I added the following code in my onCreate handler:

// Figure out what kind of display we have
  int screenLayout = getResources().getConfiguration().screenLayout;

  if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_SMALL) == Configuration.SCREENLAYOUT_SIZE_SMALL)
     LogMessage("Main onCreate", "Info", "Screen size is Small");
  else if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_NORMAL) == Configuration.SCREENLAYOUT_SIZE_NORMAL)
     LogMessage("Main onCreate", "Info", "Screen size is Normal");
  else if ((screenLayout & Configuration.SCREENLAYOUT_SIZE_LARGE) == Configuration.SCREENLAYOUT_SIZE_LARGE)
     LogMessage("Main onCreate", "Info", "Screen size is Large");

  if ((screenLayout & Configuration.SCREENLAYOUT_LONG_YES) == Configuration.SCREENLAYOUT_LONG_YES)
     LogMessage("Main onCreate", "Info", "Screen size is Long");

  // Get the metrics
  DisplayMetrics metrics = new DisplayMetrics();
  getWindowManager().getDefaultDisplay().getMetrics(metrics);
  int heightPixels = metrics.heightPixels;
  int widthPixels = metrics.widthPixels;
  int densityDpi = metrics.densityDpi;
  float density = metrics.density;
  float scaledDensity = metrics.scaledDensity;
  float xdpi = metrics.xdpi;
  float ydpi = metrics.ydpi;

  LogMessage("Main onCreate", "Info", "Screen W x H pixels: " + widthPixels  + " x " + heightPixels);
  LogMessage("Main onCreate", "Info", "Screen X x Y dpi: " + xdpi + " x " + ydpi);
  LogMessage("Main onCreate", "Info", "density = " + density + "  scaledDensity = " + scaledDensity +
     "  densityDpi = " + densityDpi);

And the results in the logs were:

Info, Main onCreate, Screen size is Normal
Info, Main onCreate, Screen size is Long
Info, Main onCreate, Screen W x H pixels: 720 x 1280
Info, Main onCreate, Screen X x Y dpi: 345.0566 x 342.23157
Info, Main onCreate, density = 2.0  scaledDensity = 2.0  densityDpi = 320

With this I realized that Android was calling this a normal display so I created a res / layout-normal-1280x720 directory with my alternate layout files.

My manifest contained:

<supports-screens
    android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"
 />

<uses-sdk android:targetSdkVersion="9" android:minSdkVersion="8" />

With these changes I was finally able to get an alternate layout to be used with this phone.

david
  • 1,311
  • 12
  • 32
Tary
  • 1,021
  • 1
  • 10
  • 13