Can the Android drawable directory contain subdirectories?

后端 未结 21 969
醉梦人生
醉梦人生 2020-11-22 04:13

In the Android SDK documentation, all of the examples used with the @drawable/my_image xml syntax directly address images that are stored in the res/drawable directory in my

相关标签:
21条回答
  • 2020-11-22 04:32

    Gradle with Android Studio could do it this way (link).

    It's in the paragraph "Configuring the Structure"

    sourceSets {
     main {
        java {
            srcDir 'src/java'
        }
        resources {
            srcDir 'src/resources'
        }
     }
    }
    
    0 讨论(0)
  • 2020-11-22 04:34

    Actually, on Android Studio it is possible. You can have nested resources as shown here :

    There is also a plugin to group resources here.

    I recommend to avoid this though.

    0 讨论(0)
  • 2020-11-22 04:34

    Yes - it does suck :) However you can use the assets folder and have sub directories in there and load images that way.

    0 讨论(0)
  • 2020-11-22 04:34

    Check Bash Flatten Folder script that converts folder hierarchy to a single folder

    0 讨论(0)
  • 2020-11-22 04:36

    With the advent of library system, creating a library per big set of assets could be a solution.

    It is still problematic as one must avoid using the same names within all the assets but using a prefix scheme per library should help with that.

    It's not as simple as being able to create folders but that helps keeping things sane...

    0 讨论(0)
  • 2020-11-22 04:36

    There is a workaround for this situation: you can create a resVector (for example) folder on the same level as default res folder. There you can add any drawable-xxx resource folders there:

    resVector
    -drawable
    -layout
    -color
    

    After that all you need is to add

    sourceSets {
            main.res.srcDirs += 'src/main/resVector'
        }
    

    into your build.gradle file (inside android { }).

    0 讨论(0)
提交回复
热议问题