In my application I have several folders and subfolders of images. They are inside drawables. How can I retrieve images from drawables subfolders?
Example:
drawable>actions>sports>soccer.png
How can I get this "soccer.png" photo?
Any help is appreciated.
Thanks!
No, the resources mechanism doesn't support subfolders in the drawable directory, so yes - you need to keep that hierarchy flat. The directory layout you showed would result in none of the images being available.
In Android Studio inside the res folder, one can find the drawable folder, layout folder, mipmap folder, values folder, etc. Among them, the drawable folder contains the different types of images used for the development of the application.
Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import. Figure 3: Select Import Drawables from the dropdown menu.
This is now (sort of) possible by using Android Studio and Gradle.
Whilst subfolders are still not possible, it is possible to separate resources into different sets and have them merged by the build system.
As an example, to simplify my project, I wanted to keep theme specific drawables separate from standard drawables.
I created a new resource folder named 'res_lighttheme' as illustrated in the picture below.
I then added a pointer to this folder to my build.gradle file like this. To add more than one just add another line to the definition.
The result is that BOTH folders are then considered to be valid destinations for resources. A build error will be generated if there is a conflict. i.e if the same resource is included in both folders.
No, the android resources mechanism doesn't support subfolders in the drawable directory, you can't put it.
I think if you having a subfolder with any items in it, within the res/drawable
folder, will cause the resource compiler to fail -- preventing the R.java
file from being generated correctly.
The only one thing is put the images in flat names like, drawable_actions_sports_soccer.png
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With