是否支持Android的布局继承(类似于Django模板)? [英] Does Android support layout inheritance (similar to Django templates)?

查看:141
本文介绍了是否支持Android的布局继承(类似于Django模板)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能是误解了如何&LT;包括&GT; &LT;合并&GT; 的工作,但根据<一个href="http://stackoverflow.com/questions/2732682/simple-example-of-merge-and-include-usage-in-android-xml-layouts">Simple例子和使用Android中的XML-布局,&LT;包括&GT; 表示采取的文件及其内容粘贴在这里

比方说,你想有3个活动都具有相同的标题,但有不同的内容。你还需要有3个XML布局文件每一项活动。每个布局的之间唯一的区别是他们定义的℃的不同的布局,包括&GT; 标记。如果我想添加页脚我不得不改变每个布局。

我正在寻找一种方式来实现的倒数,所以孩子们会布局覆盖父的特定块(的类似于Django的模板)。这样,如果我想补充一点,页脚,我只想改变家长和孩子将继续覆盖刚才的内容。

解决方案
  

比方说,你想有3个活动都具有相同的标题,但有不同的内容。你还需要有3个XML布局文件每一项活动。每个布局的之间的唯一的区别是,它们定义在标签的不同的布局。

如果你想有三个活动都具有相同的标题,你将有每个活动的一种布局文件。该文件将具有独有的活动部件,以及&LT;包括&GT; 元素公共头

  

这样的话,如果我想补充一点,页脚,我只想改变家长和孩子将继续覆盖刚才的内容。

这是不是在这个时候支持Android系统。作为janoliver表明,你可以推出自己的解决方案这一点。

I may be misunderstanding how <include> and <merge> work, but according to Simple example of and usage in Android XML-layouts., <include> means "take that file and paste its contents here".

Let's say you want to have 3 activities that all have the same header, but have different content. You'll still need to have 3 XML layout files for each activity. The only difference between each of the layout's will be that they define a different layout in the <include> tag. If I wanted to add a footer I'd have to change each layout.

I'm looking for a way to achieve the inverse, so the children layouts would override specific blocks of the parent (similar to Django templates). That way, if I wanted to add that footer, I would just change the parent and the children would continue to override just the content.

解决方案

Let's say you want to have 3 activities that all have the same header, but have different content. You'll still need to have 3 XML layout files for each activity. The only difference between each of the layout's will be that they define a different layout in the tag.

If you want to have three activities that all have the same header, you will have one layout file per activity. That file will have the widgets unique to that activity, and an <include> element for the common header.

That way, if I wanted to add that footer, I would just change the parent and the children would continue to override just the content.

That is not supported by Android at this time. As janoliver indicates, you could roll your own solution for this.

这篇关于是否支持Android的布局继承(类似于Django模板)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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