7
votes

Do I understand this correctly:

All android devices fall in one of these 4 density buckets: ldpi, mdpi, hdpi, xhdpi.

So, if a drawable resource is provided for each of these for densities (a drawable or with the same name exists in each of these folders), then it is not necessary to provide a drawable with the same name in /res/drawable or /res/drawable-nodpi.

Is my understanfing correct?

So, the only reason, why it makes sense to provide that same resource in /res/drawable would be, to make the app more future-proof, in case a new density bucket is defined for Android OS?

3

3 Answers

24
votes

Is my understanfing correct?

Through this paragraph, you are more or less correct. You go a bit "off the rails" with your next paragraph:

So, the only reason, why it makes sense to provide that same resource in /res/drawable would be, to make the app more future-proof, in case a new density bucket is defined for Android OS?

Not really.

You put resources in res/drawable/ that are intrinsically scalable (e.g., a ShapeDrawable). You put resources in res/drawable-nodpi/ that, for some reason, you do not want to be scaled to match the device density.

If Android invents a new density bucket (e.g., -uhdpi for an ultra-high density of 400dpi), Android will probably do what it does today if you skip a density bucket: scale one of your other editions. For example, if you have -xhdpi and do not have -hdpi, Android will down-sample the -xhdpi image for use on an -hdpi device.

5
votes

This is correct, as long as you have drawables in all 4 density buckets you are covered. A common practice is to make a custom drawable in /res/drawable which refers your density spanning drawables.

For example, you may want a button with different states for pressed and unpressed. First, you would include a drawable of each density for a pressed and unpressed button. Then you could create the following button_black_selector.xml in /res/drawables:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="false"
        android:drawable="@drawable/button_black"/>

    <item android:state_pressed="true"
        android:drawable="@drawable/button_black_selected" />

</selector>
0
votes

If your resource is added for all the four densities, then you're correct that you don't have to add the drawable to the folder /res/drawable. However, you've guessed correctly that it is best to have something in the default folder in the case if a new qualifier appears. Therefore, I recommend to place mdpi resources not to the /res/drawable-mdpi folder, but to the default folder instead (/res/drawable/). It is a good practice for every kind of resource.

As for the /res/drawable-nodpi folder, it is a special folder, because it is supposed to contain resources which do not scale automatically unlike all other qualifiers. Therefore you usually either use the /res/drawable-nodpi folder alone, or do not use it at all.