问题
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
回答1:
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" )
...
...
回答2:
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.
来源:https://stackoverflow.com/questions/14082868/android-does-not-honor-ldpi-qualifier