Actually, they can!
Although the steps are a bit too many, it is indeed possible to group your xml files in folders. Just follow the following steps:
Switch to Project view; you can now see all your project folders and sub-folders properly.
Backup all your layout files; at this stage you'll find them all under android/app/src/main/res/layout.
Delete the entire layout directory (android/app/src/main/res/layout). Remember to properly backup all your layout files before this step.
Right click the res directory and select "New" and then select "Directory".
Give it a name; remember the name must be entirely lowercase. Your new directory will now appear under the res folder. Let's call this directory layouts for instance.
Right click your new directory (layouts) and select "New" and then select "Directory". This way, we are creating a new sub-directory. We can give it any name we want, just remmber it must be completely lowercase.
You can repeat step 6 as many times as you want and keep creating sub-directories.
VERY IMPORTANT! Right click any of the sub-directories and select "New" and then select "Directory". YOU MUST NAME THIS DIRECTORY layout
.
Repeat this for all sub-directories.
Move all the backed-up xml files (in step 2) to the layout
directory of the folder you want to put them in.
Add the code below to your build.gradle (app) file:
sourceSets {
main {
res.srcDirs =
[
'src/main/res/layouts/layout_for_fragment',
'src/main/res/layouts',
'src/main/res'
]
}
}
Replace layouts with your sub-directory name and add as many sub-directories as are available.
- Sync project with gradle files
And that's it.. Pretty herculean but it can come in handy anytime. You may want to visit this link for more clarification.
I hope this helps.. Merry coding!