创建资源结构的最佳实践

发布于 2024-12-10 16:23:37 字数 77 浏览 0 评论 0原文

我的项目的 res/layout* 目录最近变得非常混乱,因为据我所知,不允许有子目录来改变它。所以很难在那里建立结构——你们是怎么做到的?

the res/layout* dir of my projects are getting really messy lately and as there are afaik no subdirs allowed there to change that. So it is hard to get structure in there - how do you guys do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑看君怀她人 2024-12-17 16:23:37

我不了解其他人,但就我自己而言,我喜欢使用前缀来帮助排序,本质上是代替子目录。例如,我所有的活动布局都以“activity_”开头,所有 UI 控件都以“control_”开头,通知以“notification_”开头,等等。

然后我留下一个至少具有某种结构的平面目录,例如:

activity_graph。 xml

Activity_main.xml

Activity_map.xml

control_graph.xml

control_title_bar.xml

notification_just_label.xml

notification_with_progress_bar.xml

...

这并不完美,但它对我有用。

I don't know about others but for myself I like to use prefixes to help keep things sorted, essentially taking the place of subdirectories. For example, all my activity layouts start with 'activity_' and all my UI controls start with 'control_', notifications with 'notification_', etc.

I am then left with a flat directory with at least some structure, something like:

activity_graph.xml

activity_main.xml

activity_map.xml

control_graph.xml

control_title_bar.xml

notification_just_label.xml

notification_with_progress_bar.xml

...

It's not perfect, but it works for me.

柳若烟 2024-12-17 16:23:37

抱歉,除了文档规范之外,布局文件夹内不可能有子文件夹。

只需检查此和这个问题

Sorry subfolder inside the layout folder is not possible other than docs specification.

Just check this and this and this question.

面如桃花 2024-12-17 16:23:37

另一种可能性是将应用程序的某些元素重构到库中。

例如,您可以将不相关的片段(因为片段本身应该不相关)提取到库中,将该项目标记为 Android 库(在项目属性中检查“是库”),然后在主项目中使用您自己的库。

单独的库中所需的资源将不再发生冲突,但会在构建时“扔在一起”,因此访问没有问题。

以下是相关的文档

Another possibility is to refactor some elements of your application into libraries.

For example you could extract unrelated fragments (as fragments should per se be unrelated) into libraries, mark that project as an Android library (check "Is library" in project properties) and then use your own libraries in your main project.

The resources you need within the separate libs will not collide anymore, but will be "thrown together" at build time, so access is fine.

Here are the docs for that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文