可在Android布局文件夹包含子文件夹? [英] Can the Android Layout folder contain subfolders?

查看:401
本文介绍了可在Android布局文件夹包含子文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,布局文件夹中的我的商店每个XML布局文件,因此它是管理小型项目可行和简单,但是当有大而重的项目的情况下,那么就应该有一个层次和子文件夹所需的布局文件夹内。

Right now, i stores every xml layout file inside the layout folder, so it is feasible and simple to manage small projects, but when there is a case of large and heavy projects, then there should be a hierarchy and sub-folders needed inside the layout folder.

有关如

layout
-- layout_personal
   -- personal_detail.xml
   -- personal_other.xml
--layout_address
  -- address1.xml
  -- address2.xml

喜欢同样的方式,我们希望有子文件夹的大型应用程序,那么有没有什么办法可以在Android项目中做到这一点?

Like the same way, we would like to have sub-folders for the large application, so is there any way to do so inside the android project?

我能够创建布局文件夹内的布局,个人和layout_address子文件夹,但在时机成熟时使用R.layout访问XML布局文件。 _ ,当时没有任何XML布局弹出式菜单内。

I am able to create layout-personal and layout_address sub-folders inside the layout folder, but when the time comes to access the xml layout file using R.layout._ , at that time there is no any xml layout pop-up inside the menu.

推荐答案

您可以做到这一点与摇篮。我做了一个示范项目,展示了如何:<一href="https://github.com/eskimoapps/ResourceNestingExample">https://github.com/eskimoapps/ResourceNestingExample.

You CAN do this with gradle. I've made a demo project showing how at: https://github.com/eskimoapps/ResourceNestingExample.

诀窍就是用摇篮的合并多个资源文件夹的能力,并设置资源文件夹以及在sourceSets嵌套子块。

The trick is to use gradle's ability to merge multiple resource folders, and set the res folder as well as the nested subfolders in the sourceSets block.

的怪癖是,你不能声明一个容器资源文件夹中声明该文件夹的子文件夹中的资源之前。

The quirk is that you can't declare a container resource folder before you declare that folder's child resource folders.

下面是sourceSets从演示build.gradle文件块。请注意,子文件夹首先声明的。

Below is the sourceSets block from the build.gradle file from the demo. Notice that the subfolders are declared first.

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

这篇关于可在Android布局文件夹包含子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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