1

I've got a resource in 3 different sizes. I've put one of them in drawable-hdpi, one in drawable-mdpi and one in drawable-xhdpi. Now I wonder what will happen if I run the application on a device with ldpi (or with tvdpi or nodpi if that's possible??) Would it be better maybe to put one resource in the drawable folder as well?

Darwind
  • 7,284
  • 3
  • 49
  • 48
Xander
  • 5,487
  • 14
  • 49
  • 77

3 Answers3

3

Your system will pick the "best" available resource and size it accordingly. With ldpi, it may take an hdpi and cut it in half.

With tvdpi, it may be me, but I was usually surprised with what it was picking for me.

HalR
  • 11,411
  • 5
  • 48
  • 80
  • So anyway I'll never get an exception or something if there's no resource specified? – Xander Apr 09 '13 at 16:36
  • 1
    @Merlin: For drawables, that is correct. Most other resource types require an exact match, though, as there is no automatic way to convert them. For those cases, if you request a resource and there is no match, a `ResourceNotFoundException` will occur. – CommonsWare Apr 09 '13 at 16:40
2

On the most of the devices, Android will pick the nearest available resource from the other drawable folders (like picking from ldpi or hdpi if mdpi isn't available).

However, on some devices the system may not pick up resources from other folders, due to a buggy implementation.

As a best practice, you should always keep a copy of each resource in the completely unqualified folders (drawable, values etc)/

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • "However, on some devices, especially Samsung, the system does not pick up resources from other folders." -- huh? – CommonsWare Apr 09 '13 at 16:39
  • @CommonsWare I'm basing that statement on a discussion we had in the Android chatroom last year in which someone's app kept crashing because a few Samsung devices failed to load resources from the other resource folders. I'm trying to find it, but SO's Chat search requires pretty accurate wording, which I don't really remember. – Raghav Sood Apr 09 '13 at 16:40
  • Such devices would not pass the CTS, AFAIK, and so I have serious difficulty in believing that this is actually the case. If you can identify certain devices that have this behavior, let me know, as I would like to do some research. – CommonsWare Apr 09 '13 at 16:41
  • @CommonsWare So I may be slightly mistaken, as apparently the crashes on a Samsung Galaxy Tab weren't crashes, just a loading of the wrong layout. [Here's](http://chat.stackoverflow.com/transcript/15?m=5342281#5342281) the message. – Raghav Sood Apr 09 '13 at 16:46
  • "As a best practice, you should always keep a copy of each resource in the completely unqualified folders (drawable, values etc)/" I may be wrong but when I look at the SDK-folder of Android itself, I don't see a copy of the resources in the drawable folder either or does that have a different reason? – Xander Apr 09 '13 at 16:49
  • @Merlin As CommonsWare mentioned in a comment on the other answer, drawable resources should be scaled automatically from the nearest match available, so having them in unqualified folders isn't a hard requirement. – Raghav Sood Apr 09 '13 at 16:51
  • Ah, OK. The two exceptions to the "must have an exact resource set match" are drawables (which will be upscaled or downscaled) and `-xlarge` layouts (Android will pull from `-large` if there is a match there and nothing in `-xlarge`, for some old backwards compatibility reasons). However, the layout exception is only for `-xlarge` devices pulling from `-large`; Android will not pull from `-normal` if there is nothing in `-large`, for example. – CommonsWare Apr 09 '13 at 16:54
0

You have to be careful about put images in Drawable folder without any qualifier. The images in the unqualified folder are the same that images in mdpi, so if you have a big image in the unqualified folder and you try to assign it to an ImageView in an xhdpi phone, Android will try to scale up your image, and probably it will create a "Out of memory on a XXXXXX-byte allocation"

Manolo Garcia
  • 3,785
  • 2
  • 19
  • 19