在Android的工作室组织资源 [英] Organizing resources in Android studio

查看:119
本文介绍了在Android的工作室组织资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作有很多的.xml布局文件的项目。我想组织他们在不同的文件夹中。
它看起来像资源合并将是正确的解决方案。结果
http://tool​​s.android.com/tech-docs/new -build系统/资源合并
结果
我想在分裂活动,列表视图,对话框,按钮等我的布局文件夹
搜索结果
如何修改我的项目和文件的build.gradle做到这一点?

I'm working on a project with a lot of .xml layout files. I want to organize them in separate folders. It seems like Resource Merging would be the right solution.
http://tools.android.com/tech-docs/new-build-system/resource-merging
I want to split my layout folder in activity, listview, dialog, button, etc.

How do I modify my project and build.gradle file to accomplish this ?

推荐答案

资源合并是不是真的你正在寻找这里的概念 - 该文件指定如何,如果你有多个版本的类型和口味,它们是如何结合起来,提供将内置到最终结果项目的资源的单一视图。你的情况,你可能有一个生成类型和风味,并希望在你的资源子目录,以帮助组织他们更好。

Resource merging isn't really the concept you're looking for here -- that document specifies how if you have multiple build types and flavors, how they combine to provide a single view of the project's resources that will be built into the final result. In your case, you probably have a single build type and flavor, and want to have subdirectories in your resources to help organize them better.

坏消息是,Android是不是对此非常友好。构建系统预计资源被安排在一个严格的格式,所有的布局在您的项目根目录下的单个文件夹之中,例如,它不会让你从偏离。你能做的最好的事情是有多个资源文件夹树,这将是这样的:

The bad news is that Android isn't very friendly about this. The build system expects resources to be arranged in a rigid format, with all layouts being in a single folder underneath your project root, for example, and it doesn't let you deviate from that. The best thing you can do is to have multiple resource folder trees, which would look like this:

AppModule
  + src
    + main
      + java
      + res
        + drawable
        + layout
        + ...etc...
      + extra-res
        + drawable
        + layout
        + ...etc...

每个资源子树具有其在相同的格式子目录。你并不需要在那里子目录,如果他们是空的详尽清单;只包含有你所需要的东西的人。

Each resource sub-tree has its subdirectories in the same format. You don't need to have an exhaustive list of subdirectories in there if they're empty; just include the ones that have things you need.

要完成这项工作,你需要在你的build.gradle脚本如下:

To make this work, you need to have the following in your build.gradle script:

android {
    sourceSets {
        main {
            res.srcDirs = ['src/main/res', 'src/main/extra-res']
        }
    }
}

这篇关于在Android的工作室组织资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆