Question

I am on one really big project that was started sins the time of android 1.5.

This project evolved as android was evolving and at this point supports 2.3 and above.

Now I got this problem I have a lot of drawables in drawable-hdpi,drawable-mdpi,drawable-ldpi but also in drawable folder.

Generally the concept of this 3 folders(drawable-hdpi,drawable-mdpi,drawable-ldpi) it is clear to me but my confusion comes with the images in drawable folder.

for example I have an image named myimage.png and this image is present in drawable-hdpi,drawable-mdpi,drawable-ldpi folders with resolution 72x72,48x48,36x36 respectively but this image is also present in drawable folder.

My question is why ? when does the image from drawable folder is used ? is this image forgotten to be removed ? of it is used in some cases ? I have tried to remove this image and the application works just fine. I also have put just a green color with resolution 72x72 and this image is never drawn

so can someone clarify me the existence of the drawable folder ?

I know that if I do not have the dhpi,mdpi and ldpi folders then I need to put the images in drawable but what is the point of images in drawable when this 3 folders are present ?

Thanks

EDIT

one more question, what if I have image in drawable-hdpi but not in ldpi and not i mdpi. Let say we have phone with mdpi resolution density... What will happen ?

Was it helpful?

Solution

drawable folder is used for default images if the images are not found in the respective folders then it will look into the drawable folder.

I found this phrase in the doc:

For example, imagine you have an application icon, icon.png, and need unique version of it for different locales. However, two locales, English-Canadian and French-Canadian, need to use the same version. You might assume that you need to copy the same image into the resource directory for both English-Canadian and French-Canadian, but it's not true. Instead, you can save the image that's used for both as icon_ca.png (any name other than icon.png) and put it in the default res/drawable/ directory. Then create an icon.xml file in res/drawable-en-rCA/ and res/drawable-fr-rCA/ that refers to the icon_ca.png resource using the element. This allows you to store just one version of the PNG file and two small XML files that point to it. (An example XML file is shown below.)

Please refer this link for more clearity.

OTHER TIPS

AFAIK you don't need drawable folder if you have all three types of folder (drawable-hdpi,drawable-mdpi,drawable-ldpi )with different resolution images.

As per I faced when you run the app on Android 1.5 and 2.0 if the images which is used in any layout is not available in folder 'drawable' then the project gives error "Resource not found" even if the image is present in other hdpi,mdpi or ldpi folder.

This is not about the densities there are other qualifiers as well, though in most of the cases we don't use them much. For list of qualifiers check here and here. You can use -finger -language ... etc qualifiers. In case you want to provide qualifier default resources[in this case drawable] you can opt for default drawable folder. Or many default folders without qualifiers added behind them

I think this page should help you understand better. Thank you for the question. I, myself, didn't know the answer. Basically you have 4 different versions and if no exactly matching version exists, the default one (without qualifier) is used.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top