0

I want to distinguish layout/drawables for the following two devices:

1) 7" hdpi
2) 7" ldpi

So I am using the following qualified directories:

1) layout-sw600dp-hdpi / drawable-sw600dp-hdpi
2) layout-sw600dp-ldpi / drawable-sw600dp-ldpi

But when I run on a 7" ldpi device with screen size in pixels 480x764, then Android (V4.0.3) chooses the hdpi version. Why is that? When I read the documentation, ldpi should be the better fit.

When I remove layout-sw600dp-hdpi / drawable-sw600dp-hdpi completely, it does choose 2) and everything is fine. But I also need the hdpi version.

So how can I distinguish the ldpi/hpdi version of a 7" device?

Thank you!

Andrej

Andrej
  • 161
  • 2
  • 14

2 Answers2

0

If support for multiple screens does't work then you can do it manually:

Create bools-ldpi, bools-hdpi with flags:

bools-ldpi contains field with name "lowDp" = true bools-hdpi contains field with name "highDp" = true etc.

In code you make if-else if-else :

if ( getresource "lowDp" ) 
    ...
else if ( getresource "highDp" ) 
    ...
...
RobertM
  • 287
  • 1
  • 6
  • That would be too much work. I was hoping for an easier soltion to force Androids "best choice". – Andrej Dec 29 '12 at 16:08
  • Try to change name: layout-sw600dp-ldpi to layout-sw600dp, and drawable-sw600dp-ldpi to drawable-sw600dp. Then these directories will be default and for specified devices other directories will be used. – RobertM Dec 29 '12 at 17:09
  • Hi RobertM. I tried this but it does not work. Android still prefers the -hdpi for the 7" ldpi device. Is this a bug in Android? – Andrej Dec 30 '12 at 00:14
  • I can still not find any way to distinguish a 7" ldpi and hdpi. Why is that? The 7" ldpi device has device metrics of 480x764 instead of 480x800. Could that be of any influence? – Andrej Dec 30 '12 at 02:18
  • Well, I read somewhere that regardless the pixels per inch read from the DisplayMetrics, the manufacturer still decides its preferred resolution which might be different. I guess I will have to to this manual. Also: http://code.google.com/p/android/issues/detail?id=37187 – Andrej Dec 30 '12 at 03:33
0

I cannot find the reference anymore but I think that I've read somewhere that you shouldn't use a smallestWidth (swdp) or Avilable width (wdp) at the same time than a Screen pixel density (ldpi, hdpi, etc.) and that the result of such a combination was indefinite.

If you have different drawables to be displayed for different Screen pixel density, you should put them in their own drawable repertory like drawable-ldpi/icon.png or drawable-hdpi/icon.png, separate from the layout repertories and keep only the swdp term for these layout repertories.

SylvainL
  • 3,926
  • 3
  • 20
  • 24