Can the Android layout folder contain subfolders?

前端 未结 20 2885
暗喜
暗喜 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:54

    Within a module, to have a combination of flavors, flavor resources (layout, values) and flavors resource resources, the main thing to keep in mind are two things:

    1. When adding resource directories in res.srcDirs for flavor, keep in mind that in other modules and even in src/main/res of the same module, resource directories are also added. Hence, the importance of using an add-on assignment (+=) so as not to overwrite all existing resources with the new assignment.

    2. The path that is declared as an element of the array is the one that contains the resource types, that is, the resource types are all the subdirectories that a res folder contains normally such as color, drawable, layout, values, etc. The name of the res folder can be changed.

    An example would be to use the path "src/flavor/res/values/strings-ES" but observe that the practice hierarchy has to have the subdirectory values:

    ├── module 
       ├── flavor
          ├── res
             ├── values
                ├── strings-ES
                   ├── values
                      ├── strings.xml
                   ├── strings.xml
     
    

    The framework recognizes resources precisely by type, that is why normally known subdirectories cannot be omitted.

    Also keep in mind that all the strings.xml files that are inside the flavor would form a union so that resources cannot be duplicated. And in turn this union that forms a file in the flavor has a higher order of precedence before the main of the module.

    flavor {
            res.srcDirs += [
                "src/flavor/res/values/strings-ES"
            ]
    }
    

    Consider the strings-ES directory as a custom-res which contains the resource types.

    GL

提交回复
热议问题