Android的布局:是可重用组件的用户界面可能吗? [英] Android Layout: Is reusable component UI possible?

查看:139
本文介绍了Android的布局:是可重用组件的用户界面可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会preface这一带,我刚开始学习Android的如此温柔。 我来自一个ASP.NET / Silverlight的背景,所以我一直在寻找沿控制线的东西。

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.

我想重用的布局(一个ListView项模板)的其它布局。

I want to reuse a layout (a ListView item template) in other layouts.

这样的,在我的其他的布局我可以再补充< myListItem /> 来显示它

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?

推荐答案

这是非常有可能的;你只需要使用&LT;有/&GT; 标记。基本上,你把你的布局在文件中,那么你做的:

This is very possible; you just need to use the <include /> tag. Basically, you put your layout in a file, then you do:

<include layout="@layout/my_list_item_template" />

罗曼盖伊进入详细讨论如何在这里使用它:<一href="http://www.curious-creature.org/2009/02/25/android-layout-trick-2-include-to-reuse/">http://www.curious-creature.org/2009/02/25/android-layout-trick-2-include-to-reuse/

安卓文档

(我假设你想要的是一个可重复使用的布局,而不是自定义组件,所不同的是,可重复使用的布局就像是重复使用标准组件的片段,而自定义组件使用,当你需要扩展的功能一个特定的部件,像一个TextView或按钮,如果你想有一个自定义组件,那么你就必须做很多跑腿到埃里希·道格拉斯的回答更多关于这一点。)

(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.)

这篇关于Android的布局:是可重用组件的用户界面可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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