Can the Android layout folder contain subfolders?

前端 未结 20 2819
暗喜
暗喜 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 04:00

    A way i did it was to create a separate res folder at the same level as the actual res folder in your project, then you can use this in your apps build.gradle

    android {
        //other stuff
    
        sourceSets {
            main.res.srcDirs = ['src/main/res', file('src/main/layouts').listFiles()]
        }
    }
    

    then each subfolder of your new res folder can be something relating to each particular screen or something in your app, and each folder will have their own layout / drawable / values etc keeping things organised and you dont have to update the gradle file manually like some of these other answers require (Just sync your gradle each time you add a new resource folder so it knows about it, and make sure to add the relevant subfolders before adding your xml files).

提交回复
热议问题