Can the Android layout folder contain subfolders?

前端 未结 20 2823
暗喜
暗喜 2020-11-22 03:10

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

20条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 03:45

    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 ids (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.

提交回复
热议问题