Today I'm talking about storing layouts in Android application in different folders. Because sometimes it can be a problem store many layouts in one folder. If your project have more then 30 layouts it's a problem find a required layout. As solution for this problem you can store your layouts in different folders. You can separate your layouts to activity layouts, fragment layouts, adapter layouts, etc.

For instance, you can separate layout like this

Demo: Separate layout folders

For it you must to do some steps:

  1. Create Directory in res folder which called layouts.
  2. Create Resource Folder in layouts folder which called activity (To create a Resource folder you should choose New -> Folder -> Res Folder, after it write the correct path as example src/main/res/layouts/activity);
  3. Create Directory in activity folder which is called layout.
  4. Do the same for fragment and adapter folders;
  5. Move your layouts for new folders.

Last step use must update build.gradle file for your project.

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        ...
    }
    buildTypes {
        ...
    }
    sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java', 'apt_generated']
            aidl.srcDirs = ['src/main.aidl', 'apt_generated']
            assets.srcDirs = ['src/main/assets']
            res.srcDirs = [
                'src/main/res/layout/activity',
                'src/main/res/layout/fragment',
                'src/main/res/layout/dialog',
                'src/main/res/layout/adapter',
                'src/main/res'
            ]
        }
    }
}

After compile your project all link will works correctly.

If you want to use different layout mode, as example portrait mode, landscape mode, etc. You need create folders like this.

Demo: Separate layout folders

Note: this solution works just for Project perspective.