30

I have a fairly complex android app, the contents of the 'layout' folder is becoming increasingly large. I've tried to organise the individual layout xml files into sub folders e.g. layout/buttons/, layout/activity/, layout/views/ etc. This doesn't seem to work, the content of the folders in not parsed into the R. class.

Is there a way to do this?

Thanks!

longhairedsi
  • 3,133
  • 2
  • 28
  • 28
  • 1
    Possible duplicate of [Can the Android Layout folder contain subfolders?](http://stackoverflow.com/questions/4930398/can-the-android-layout-folder-contain-subfolders) – Code-Apprentice Nov 22 '16 at 11:31

3 Answers3

22

I don't think you're going to be able to do this. I believe that it only supports certain folder names like layout-large, layout-mdpi, layout-hdpi, layout-fr, etc. You can use more than one of these modifies as well like layout-fr-hdpi-large.

This page shows all of the allowed modifiers

http://developer.android.com/guide/topics/resources/providing-resources.html

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • 2
    He is talking about subfolders, e.g. `layout-hdpi/buttons/mybutton.xml`, not the resource-folders itself. – KingCrunch Dec 31 '10 at 16:56
  • 3
    Still, this is unsupported. I wish you could do this as well. With a custom UI, you can end up with a LOT of layouts and drawable resources in one folder. Hopefully they add this in a future release of the SDK> – Kevin Coppock Dec 31 '10 at 17:13
  • 5
    Marked as answer as this technically correct, this is not currently possible. I'm exploring alternative such as packaging up my views into separate projects. – longhairedsi Jan 07 '11 at 13:36
18

Another option is to use a prefix for your different views. Is not as nice as having different folder but it can introduce some order.

Carles Company
  • 7,118
  • 5
  • 49
  • 75
9

Now with Android Studio and Gradle, you can have multiple resource folders in your project. Allowing to organize not only your layout files but any kind of resources.

It's not exactly a sub-folder, but may separte parts of your application.

The configuration is like this:

sourceSets {
    main {
        res.srcDirs = ['src/main/res', 'src/main/res2']
    }
}

Check the documentation.

Androiderson
  • 16,865
  • 6
  • 62
  • 72