Search code examples
androidresourcesdrawableorganization

Organize Contents of drawable-hdpi (mdpi, ldpi, etc.) via folders


My android project uses many images, and I have images for different DPIs as well. Currently, all the images reside in their respective folders in project, i.e. drawable-hdpi, drawable-ldpi and so on.

It works, but is it possible to have them organized in folders within their drawable folder? like:

drawable-hdpi
    > common
    > activity1
    > activity2


drawable-mdpi
    > common
    > activity1
    > activity2

And, I could access them as, R.drawable.common.image1, R.drawable.activity2.icon1, and so on.


Solution

  • No, the resources mechanism doesn't support subfolders in the drawable directory, so - you need to keep that hierarchy flat.

    Can the Android drawable directory contain subdirectories?

    As of Android 2.2, this doesn't cause a compiler error, but any subdirectories are ignored when generating the R class. This really sucks, and makes it hard to manage larger projects.