Can the Android drawable directory contain subdirectories?
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.
From my own experiments it seems that 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.
Any way to insert sub-directories in Drawable? (Android Studio)
No, the Android resources mechanism doesn't support any custom directory or subdirectory yet (instead of the assets for example).
However, you can implement a structure similar to:
|--- res
|
|--- circles
| |--- drawable
| |--- my-circle.xml
|
|--- triangles
| |--- drawable
| |--- my-triangle.xml
|
|--- selectors
|--- drawable
|--- my-selector.xml
And with Gradle you can add src/main/circles
, src/main/triangles
and src/main/selectors
to your res
directories.
e.g.
android {
sourceSets {
main.res.srcDirs += ['src/main/circles', 'src/main/triangles', 'src/main/selectors']
}
}
Is it possible to use sub folders in drawables in Android?
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
.
Possible to create subfolders in drawable folder in Android Studio?
No, Android expects all the files to be in a single directory, and does not allow subfolders to be used.
Most apps use a naming convention in place of subfolders, so in your example you might end up with a list of files:
- intro_welcome.png
- intro_background.png
- loading_splashscreen.png
- actionbar_delete.png
Is it possible to create multiple directories for drawable in res?
You can't create subfolders for drawables in the res/drawable folder.
See this question here in SO.
Can the Android drawable directory contain subdirectories?
drawable/assets can you have a subfolder in that directory?
You cannot create subdirectories in a resource directory. res/drawable-hdpi/
can hold images, but not directories of images, for example.
assets/
can have whatever directory structure you want.
Can the Android layout folder contain subfolders?
You CAN do this with gradle. I've made a demo project showing how.
The trick is to use gradle's ability to merge multiple resource folders, and set the res folder as well as the nested subfolders in the sourceSets block.
The quirk is that you can't declare a container resource folder before you declare that folder's child resource folders.
Below is the sourceSets block from the build.gradle file from the demo. Notice that the subfolders are declared first.
sourceSets {
main {
res.srcDirs =
[
'src/main/res/layouts/layouts_category2',
'src/main/res/layouts',
'src/main/res'
]
}
}
Also, the direct parent of your actual resource files (pngs, xml layouts, etc..) does still need to correspond with the specification.
Related Topics
Linear Layout and Weight in Android
Android Gallery on Android 4.4 (Kitkat) Returns Different Uri For Intent.Action_Get_Content
What's the Difference Between the Various Methods to Get an Android Context
How to Create Our Own Listener Interface in Android
Android Respond to Url in Intent
Get Screen Width and Height in Android
Detect Home Button Press in Android
Removing an Activity from the History Stack
Android Basics: Running Code in the Ui Thread
Simple Android Grid Example Using Recyclerview With Gridlayoutmanager (Like the Old Gridview)
How to Scale an Image in Imageview to Keep the Aspect Ratio
Post Multipart Request With Android Sdk
How to Detect When Wifi Connection Has Been Established in Android