Gavriel
Gavriel

Reputation: 19247

Is there a point having res/drawable-ldpi in android?

I'm trying to understand http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources and I wonder if there's a point having both drawable and drawable-ldpi? The reason I ask is because I copied some of my drawables from different examples. I have the icons from Holo theme in drawable-mdpi, drawable-hdpi, drawable-xhdpi, but the launcher icon exists also in drawable-ldpi (however there are no other files in drawable-ldpi). I also have a couple of custom drawables that only exist in drawable directory.

Here's an example:

res/drawable/x.png
res/drawable-ldpi/ic_launcher.png
res/drawable-mdpi/ic_launcher.png
res/drawable-mdpi/ic_download.png
res/drawable-hdpi/ic_launcher.png
res/drawable-hdpi/ic_download.png
res/drawable-xhdpi/ic_launcher.png
res/drawable-xhdpi/ic_download.png
res/drawable-xxhdpi/ic_launcher.png

Do I understand correctly that this is a bad configuration, as if my app happens to run on an ldpi device it will crash, because it's missing the ic_download drawable? So what is the correct solution? Do I HAVE TO resize all of my drawables to ldpi? Or should I just add the smallest existing version of EACH drawable to drawables/ to be on the safe side?

Upvotes: 8

Views: 7380

Answers (6)

AndroidEngineX
AndroidEngineX

Reputation: 1501

There is no need for ldpi density folder as that is not used anymore. See the lint description for the same

"Low density is not really used much anymore, so this check ignores " + "the ldpi density. To force lint to include it, set the environment " + "variable ANDROID_LINT_INCLUDE_LDPI=true. For more information on " + "current density usage, see " + "https://developer.android.com/about/dashboards",

Also if you check the android official distribution dashboard, you will find the usage of ldpi to be 0%

Upvotes: 0

mlepage
mlepage

Reputation: 2472

For what it's worth, if you look at the AOSP source for KitKat, some of the built-in apps do not have LDPI resources anymore. So by that token I'd say, no they are not required anymore.

Upvotes: 0

thiagolr
thiagolr

Reputation: 7027

Only 10% of the devices are ldpi and this number is decreasing over time. Source: http://developer.android.com/about/dashboards/index.html

It is not required to have images for all the densities, only one is enough. The system will scale it up/down when needed. So the best approach is to have images for the highest density supported (xhdpi or xxhdpi).

I personally only use xhdpi images!


If you put all images on xhdpi folder, the app won't crash because of missing images on other densities. The image will be resized to a smaller size for all the other densities, thus it will not lose its characteristics.

Google's recommendation is useful when you are creating different images for each resolution and not just resizing it. Example: ldpi icon (36x36) = only a simple baseball / xhdpi icon (96x96) = a bat hitting a baseball

One more detail, if you put an image on the default folder (mdpi) it will scale it up 2x times for xhdpi devices and you might have OOM issues. If you put the image on the xhdpi folder it will scale it down by half.

In practice it is not needed, but you may add them if you desise a (very?) small performance improvement and you don't mind a bigger APK.

Upvotes: 17

Martin Cazares
Martin Cazares

Reputation: 13705

Let me explain how exactly the hierarchy of folders works and why is important to set the proper image in the proper folder.

The way android will pick a file is based on the device running the app density of pixels, it will start on that density (e.g. hdpi), if it doesn't find the resource there it will go down the whole hierarchy until the "default" drawable, you could be missing resources in different densities folders and the OS won't complain, but if the resource is not found on the default folder then the OS will let you know that there's a problem, there's some hard to find bugs related to this issue, let me put an example, lets say you have a resource in drawable-hdpi folder only, the compiler wont complain because theres a resource with the ID you specified and if you run the app on hdpi devices you won't have any problems, however if the app runs on a ldpi device, the app will crash because the OS will try to find it on ldpi folder then on default and none of them will contain the resource causing crash, thats why most people just skip that part and set everything in "drawable"(default folder), because the OS will always find it there, no matter what density you are working on, but an important point to take on count here is, when you don't have the proper resource for the proper density of pixels, the OS itself will try to do a "resize" of the only resource found taking huge amounts of memory just because of the calculation, in one of the projects i worked not having the proper resources for the proper density of pixels was causing OutOfMemoryError because the OS was resizing all of the assets letting few space for other actions...

Regards!

Upvotes: 1

Piovezan
Piovezan

Reputation: 3223

In a ldpi device your app will retrieve drawables from the drawable folder if it can't find the appropriate drawables in the drawable-ldpi folder, however it may cause OutOfMemoryError if the drawables are too big. This is why you should use the drawable-ldpi folder with properly resized drawables.

Upvotes: 1

Y2i
Y2i

Reputation: 3878

When Eclipse creates launcher icons, it only creates them for mdpi, hdpi, xhdpi, and xxhdpi. Based on that, I would assume that creating ldpi icon is not necessary and that mdpi will be scaled down automatically

Upvotes: 1

Related Questions