Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 963
Gavriel Avatar asked Jun 06 '13 17:06

Gavriel


1 Answers

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.

like image 65
thiagolr Avatar answered Sep 17 '22 12:09

thiagolr