Issue
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?
Solution
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.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.