Creating of large Android project will lead to numerous layout files in res folder. Can I just group them by creating subfolders? Is is possible in Android?
For example what I have now:
res/
/layout/
/Some large list there
And what I wanted to achieve:
res/
/layout/
/subfolder1/
/layout1.xml
/view1.xml
......
/subfolder2
/another_layout.xml
/another_view.xml
I tried to do this but got error of compilation. Appreciate your help.
The answer is YES, but only if you're using Android Studio and thus the Gradle Build System.
Btw: There's also a Thread on code.google.com discussing this issue (Issue 2018: R.java should recognize resources in sub-directories).
It has been closed by a Project Member with the following statement:
Marking this as released. This is largely possible in the Gradle build system as it exists today, and we won't be implementing this for other build systems.
So how can you realise this in Android Studio? Here's how:
build.gradle
file like this:android {
// Other stuff
sourceSets {
main {
res.srcDirs =
[
'/src/main/res/layout/subfolder1',
'/src/main/res/layout/subfolder2',
'/src/main/res'
]
}
}
}
Result would look like this:
Some things to note:
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