Android 布局:可重用组件 UI 可能吗?
我将以此作为序言,我刚刚开始学习 Android,所以要温柔。 我有 ASP.NET/Silverlight 背景,所以我一直在寻找与控件相关的东西。
我想在其他布局中重用布局(ListView 项模板)。
这样,在我的其他布局中,我只需添加
即可显示它。
这是可能的吗?或者有更好的方法吗?
I'll preface this with, I've just started learning Android so be gentle.
I come from an ASP.NET / Silverlight background so I was looking for something along the lines of controls.
I want to reuse a layout (a ListView item template) in other layouts.
Such that in my other layouts I can just add <myListItem />
to show it.
Is this, or anything like it possible? or are there better ways?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是很有可能的;您只需要使用
标签即可。基本上,您将布局放入文件中,然后执行以下操作:Romain Guy 详细介绍了如何使用它:http://www.curious-creature.org/2009/02 /25/android-layout-trick-2-include-to-reuse/
(Android 文档)
(我假设您想要的是可重用布局,而不是自定义组件。区别在于,可重用布局就像重用标准组件的片段,而自定义组件则使用当您需要扩展特定小部件的功能时,例如 TextView 或 Button,如果您想要自定义组件,那么您将不得不对 Erich Douglass 的答案进行更多的跑腿工作以获取更多信息。)
This is very possible; you just need to use the
<include />
tag. Basically, you put your layout in a file, then you do:Romain Guy goes into detail on how to use it here: http://www.curious-creature.org/2009/02/25/android-layout-trick-2-include-to-reuse/
(Android documentation)
(I am assuming that what you want is a reusable layout, not a custom component. The difference being, a reusable layout is like reusing snippets of standard components, whereas a custom component is used when you need to extend the functionality of a particular widget, like a TextView or Button. If you want a custom component, then you'll have to do a lot more legwork to Erich Douglass' answer for more on that.)