views:

909

answers:

2

With Android, you can define different resources for different phone attribute by naming res directories appropriately. I need to be able to support different layouts for 480x800 and 480x854. I figured I could have one set of resources stored in the layout-hdpi-v4 directory and another in layout-long-hdpi-v4. However, both resolution seem to think that they are long (at least based on the emulator, which I understand may not reflect devices accurately).

Is there another way in which I can distinguish between the two resolutions/aspect ratios?

+1  A: 

If you want to determine the screen size in code, DisplayMetrics will help

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

You can look at the fields widthPixels and heightPixels.

However, read too the Best Practices for Screen Independence.

Ewan Todd
I'm familiar with all that stuff. It's a unique case where I'm porting an iPhone app that requires a view to be aligned along the bottom. At the same time my layout needs to extend longer than the screen on the 480x800 to avoid having the background resize to a different aspect ratio. Otherwise, the use of layout_alignParentBottom would do the trick.
A: 

There is a screen size qualifier, though its use is deprecated and recommended to not be used:

layout-800x480,layout-854x480

Otherwise, it doesn't look like there is a supported way in resource naming that can differentiate the two resolutions, besides using flexible layouts to expand into the extra screen space.

rekursiv
Note, the hdpi qualifier will trump the res qualifier by itself. So, if you decide to go this unrecommended route, you will need to make it layout-hdpi-854x480. Thanks for the answer.