-1

I have my image resources in the various mipmap folders (mipmap-xhdpi, mipmap-xxhdpi, etc.) My project has hundreds of images (and growing) and it is becoming cumbersome that they are all in a single level in each directory.

I want to create a subfolder, such as "sprites" that I can reference in code with something like

R.mipmap.sprites.sprite_name

How can I create usable sub-folders in my mipmap folders?

When I create a new directory inside of a mipmap folder (using New -> Directory), the directory and its contents are invisible to anywhere that I am specifying a resource, namely:

• In the design-view of my xml layout, when I am browsing for an image resource for a background or an image button, the sub folders are hidden.

• In code, when I am specifying an image resource (R.... the subfolders are ignored).

Is there a correct way to do this? There appear to be some other directory options, Under the New -> Folder category, I have:

Assets folder, described as "create a source root for assets to be included in the apk," but I don't want a root, I want a subdirectory.

Res Folder, "source root for android resource files" 1. I don't see how this is different than an asset and 2. again, I don't want a root.

There are also several other folder types listed, that I am not familiar with.

If this cannot be accomplished, what is the correct way to include (and organize) hundreds (or thousands) of image resources in a project? Is the only way to do it really to have them all in a single directory?

chiliNUT
  • 18,989
  • 14
  • 66
  • 106
  • 2
    Unfortunately this is not supported, all files inside the "res" folder subfolders must be at the top level. – Egor May 17 '15 at 21:49
  • @Egor than what is the "proper" way to include a large number of image resources in an application? It seems silly that the only way is to have hundreds (or thousands) of images in a single directory – chiliNUT May 17 '15 at 21:53
  • 1
    I am using the `assets` folder to store hundreds of icons in my app. You can create a subfolder, for examle `assets/sprites`. – ByteHamster May 17 '15 at 22:01
  • @ByteHamster the mipmaps are special because the app will display images of a different resolution depending on the device resolution. Can I still accomplish that with the assets folder? – chiliNUT May 17 '15 at 22:03
  • 1
    AFAIK, it is not possible automatically. You could write a function that checks the current density and chooses the corresponding folder. – ByteHamster May 17 '15 at 22:06

2 Answers2

3

How can I create usable sub-folders in my mipmap folders?

You can't. Resource directories of any time, mipmap or otherwise, cannot have subdirectories.

what is the correct way to include (and organize) hundreds (or thousands) of image resources in a project? Is the only way to do it really to have them all in a single directory?

If you are going to go with resources, then yes, though I would put them in drawable directories. mipmap is mostly for launcher icons.

the mipmaps are special because the app will display images of a different resolution depending on the device resolution

No. mipmap and drawable resources support resource resampling at runtime, but it is based on density, not resolution.

As ByteHamster notes, you can put whatever sort of directory structure you want in assets/, though you will need to put the appropriate values into BitmapFactory.Options to help with the resampling based on density.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

Yes, you must keep all the resources in a single folder because, as you may know, different folders are used to target different device classes.

The right way to organise your resources in by prefix: as stated in the official Android documentation, you should use prefixes to make the resources appear in a meaningful order.

manfcas
  • 1,933
  • 7
  • 28
  • 47