Organize layout XMLs in Android project resources (res)

2

Problem

My project is growing and with it, the amount of files in the layout folder, and it is already becoming somewhat difficult to find a specific file, since they are not grouped in any way, just in alphabetical order.

Then I tried to create subfolders for layout, to separate them by sessions, for example:

layout
-- layout_grid
   -- grid_detail.xml
   -- grid_item.xml
--layout_form
   -- form1.xml
   -- form2.xml

But this does not seem to be supported by Android since xml's are no longer found.

Questions

  • I wonder if it's possible to somehow create subfolders for layout

  • If the answer to the previous question is No , then if there is any     another good practice for organizing the layout folder?

  • asked by anonymous 14.04.2014 / 15:42

    3 answers

    7
    Unfortunately, the answer is really no (at first).

    Android does not support subfolders in this case - it only accepts files within pre-defined folders. What I have seen several times is to name the files with a prefix, as if separated by the application packages, such as "user_", "venda_", etc ...

    However , you can use subfolders with the help of Gradle, configuring it to recognize the subfolders you have created. You can see an example here .

        
    14.04.2014 / 16:01
    2

    I organize this way:

  • If the layout is referring to a Activity , then the name will be activity_nome_da_classe
  • If the layout is referring to a Fragment , then the name will be fragment_nome_da_classe
  • If the layout refers to an item of ListView , then the name will be list_item_nome_da_classe
  • And so on ... I think you could understand, right? It's just a suggestion.

        
    10.05.2014 / 04:13
    2

    There is actually a way to organize resources through sub-folders.

    In the gradle file, you'll need to use the sourceSets tag:

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

    So, the project will contain two resources, res and res2 folders, and within each one there will be the usual drawable , layout , values , and so on.

    For a better example, check out this site: Organize Res folder .

        
    12.12.2016 / 19:28