views:

1759

answers:

3

Received an email from my first Motorola Droid user. The new 480x854 resolution introduced in Android 2.0 (as opposed to 320x480) is wreaking havoc with my user interfaces. Everything is smaller and ill-positioned.

I was under the impression that if we follow the XML layout guides we were resolution-safe, as no absolute coordinates are used. Does anyone have experience in making the UI resolution-safe? Will we need a main.xml for each resolution times each orientation?

+6  A: 

Which dimension units did you use?

AFAIK using dp and sp should keep you safe.

From documentation:

dp Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".

sp Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.

Marcin Gil
Thank you Marcin, I did not know that. Will go read about it asap! Regards
BeMeCollective
In case the docs don't make it quite clear: use sp for font sizes, and dp for sizes of things that aren't fonts, like paddings, margins, and dimensions.
Klondike
+1  A: 

Aside from the resolution difference, the other thing to consider is that the Droid's WVGA screen has a different aspect ratio from previous devices like the G1. In many older apps that I've downloaded, this manifests as a gap at the bottom of the screen, or elements that are vertically misaligned in portrait mode. You may want to try running your app in the emulator with a WVGA skin to check for any hidden assumptions that your layout makes about the aspect ratio.

Joe Hughes
+5  A: 

The eclair emulator works wonders for these issues, also make sure to read:

http://developer.android.com/guide/practices/screens_support.html

Your application responds to different resolutions based on many factors, even the min-sdk. Also, from the page, are some best practices:

  1. Prefer wrap_content, fill_parent and the dip unit to px in XML layout files
  2. Avoid AbsoluteLayout
  3. Do not use hard coded pixel values in your code
  4. Use density and/or resolution specific resources
Ralphleon
+1 for linking to the Android documentation on the matter.
Steven Oxley