开发者

Making subfolders in a resource folder

Is it possible to make subfolders in the resource folders in the Android project? I have about 200 images (thumbnails) that I need 开发者_开发知识库in my project and I could add them in the drawable-mdpi, but it would be better to not mix these images with the other ones. Something like drawable-mdpi --> thumbs --> all images here.


No this is not allowed. You are only allowed to make folders specified by the android documentation.

The allowed sub folder names are specified in the link. Android generates the R.java based on these structures and putting sub folders can cause errors.


actually, there are mechanisms in place that allow the R.java file to be generated when there are folders with non-standard names in the res folder.

(i ran into this wanting to share a git repo as a submodule of both an iOS and Android project, but not wantint the Android project to pick up files that resided in a folder i designated.)

aapt is the tool that creates the R.java file, and it can be invoked with the --ignore-assets argument. there is a set of defaults for this found in the google source documentation, or a less verbose description simply by invoking aapt from the command-line without any arguments (or --help, which isn't a valid argument, but presents help nevertheless). using the line aapt.ignore.assets=xxx in an ant.properties file in your Android project will accomplish pretty much the same thing, depending upon your needs or preferences.

if you do not have a build.xml or other mechanism that forces usage of ant (which i do not), one of the aapt --ignore-assets defaults is <dir>_*, which means ignore any folders starting with _.

this was my fallback: i created a directory called _iOS_retina and placed all of my @2x files in there. (in Xcode, i can simply pull in resources from wherever they reside). the default invocation of aapt simply ignores it. to further streamline my project, i also updated my .project file to contain a resource filter that ignores this folder, and thus it doesn't take any space in my eclipse environment, either.

    <filteredResources>
        <filter>
            <id>1371429105277</id>
            <name></name>
            <type>26</type>
            <matcher>
                <id>org.eclipse.ui.ide.multiFilter</id>
                <arguments>1.0-name-matches-true-false-_iOS_retina</arguments>
            </matcher>
        </filter>
    </filteredResources>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜