Can the Android drawable directory contain subdirectories?

后端 未结 21 936
醉梦人生
醉梦人生 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:36
    #!/usr/bin/env ruby
    
    # current dir should be drawable-hdpi/ etc
    
    # nuke all symlinks
    Dir.foreach('.') {|f|
        File.delete(f) if File.symlink?(f)
    }
    
    # symlink all resources renaming with underscores
    Dir.glob("**/*.png") {|f|
        system "ln -s #{f} #{f.gsub('/', '_')}" if f.include?("/")
    }
    
    0 讨论(0)
  • 2020-11-22 04:38

    Use assets folder.

    sample code:

    InputStream is = null;
    try {
        is = this.getResources().getAssets().open("test/sample.png");
    } catch (IOException e) {
        ;
    }
    
    image = BitmapFactory.decodeStream(is);
    
    0 讨论(0)
  • 2020-11-22 04:40

    I like to use a simple script to flatten an organized directory structure provided by designers to something that can be used to generate an R file.

    Run with current path in drawable-hdpi:

    #! /bin/bash
    DIRS=`find * -type d`
    for dir in ${DIRS} ; do 
      for file in `ls ${dir}` ; do
        mv ${dir}/${file}  ${dir}_${file};
      done 
      rmdir ${dir};
    done
    
    0 讨论(0)
  • 2020-11-22 04:40

    One way to partially get around the problem is to use the API Level suffix. I use res/layout-v1, res/layout-v2 etc to hold multiple sub projects in the same apk. This mechanism can be used for all resource types.

    Obviously, this can only be used if you are targeting API levels above the res/layout-v? you are using.

    Also, watch out for the bug in Android 1.5 and 1.6. See Andoroid documentation about the API Level suffix.

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

    It is possible to have multiple drawable folders by having an extra folder parallel to 'res' with a subdirectory 'drawable' and then add following to gradle:

    sourceSets {
        main {
            res.srcDirs 'src/main/<extra_res>'
        }
    }
    

    Tested with gradle 6.5.1

    0 讨论(0)
  • 2020-11-22 04:41
    1. Right click on Drawable
    2. Select New ---> Directory
    3. Enter the directory name. Eg: logo.png(the location will already show the drawable folder by default)
    4. Copy and paste the images directly into the drawable folder. While pasting you get an option to choose mdpi/xhdpi/xxhdpi etc for each of the images from a list. Select the appropriate option and enter the name of the image. Make sure to keep the same name as the directory name i.e logo.png
    5. Do the same for the remaining images. All of them will be placed under the logo.png main folder.
    0 讨论(0)
提交回复
热议问题