Right now, I\'m storing every XML layout file inside the \'res/layout\' folder, so it is feasible and simple to manage small projects, but when there is a case of large and
Cannot have subdirectories (easily) but you can have additional resource folders. Surprised no one mentioned it already, but to keep the default resource folders, and add some more:
sourceSets {
main.res.srcDirs += ['src/main/java/XYZ/ABC']
}
Top answers have several disadvantages: you have to add new layout paths, AS places new resources to res\layouts
folder instead of res\values
.
Combining several answers I wrote similar:
sourceSets {
main {
res.srcDirs =
[
'src/main/res',
file("src/main/res/layouts/").listFiles(),
'src/main/res/layouts'
]
}
}
I made folders with this article: http://alexzh.com/tutorials/how-to-store-layouts-in-different-folders-in-android-project/. In order to create subfolders you should use this menu: New > Folder > Res Folder.
UPDATE
After a couple of weeks I found that changes in resources are not noticed by Android Studio. So, some weird bugs appear. For instance, layouts continue to show old sizes, margins. Sometimes AS doesn't find new XML-files (especially during run-time). Sometimes it mixes view id
s (references to another XML-file). It's often required to press Build > Clean Project
or Build > Rebuild Project
. Read Rebuild required after changing xml layout files in Android Studio.
I use Android File Grouping plugin for Android Studio.It doesn't really allows you to create sub-folders, but it can DISPLAY your files and resources AS they are in different folders. And this is exactly what I wanted.
You can install "Android File Grouping" plugin by
Windows:
Android Studio -> File -> Settings -> Plugins.
Mac:
Android Studio -> Android Studio Tab (Top Left) -> Preferences -> Plugins -> Install JetBrains Plugin..
For Mac, I was able to test it and was not able to search for the plugin. So I downloaded the plugin from here and used the Install plugin from disk
option from the above setting.
Now we can easily do with JetBrains plugin called "Android File Grouping"
check out this link
Android File Grouping
Well, the short answer is no. But you definitely can have multiple res
folders. That, I think, is as close as you can get to having subfolders for the layout
folder. Here's how you do it.
sourceSets {
main {
res.srcDirs =
[
'src / main / res / layout / layout_1'
'src / main / res / layout / layout_2',
'src / main / res'
]
}
}