如何设置被包括在另一布局的Andr​​oid布局内属性? [英] How to set attributes inside Android layout that is included in another layout?

查看:138
本文介绍了如何设置被包括在另一布局的Andr​​oid布局内属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有由一个ImageView的和TextView的对象包装了的LinearLayout内的复合部件。由于这是用我的内部活动之一,好几次我把它作为单独的布局,包括它的主要布局内多次。我知道你可以覆盖视图ID为从主布局标签所包含的布局。我的问题是,是否有可能把事情像图片来源和TextView的字符串从XML主要布局?当然,我能做到这一点编程,但我不知道是否有可能纯粹XML ...

I have a composite widget that consists of an ImageView and TextView object wrapped up inside a LinearLayout. Since this is used several times inside one of my activities I made it a separate layout and include it multiple times inside the main layout. I understand you can override the view id for the included layout from the tag in the main layout. My question is, is it possible to set things like the image source and textview string from the main layout in XML? Sure, I could do this programmatically but I was wondering if it was possible purely in XML...

推荐答案

从的文档

您可以包括任何其它布局
  属性中的<&包括GT;是
  通过在根元素支持
  包括布局,他们将覆盖
  那些在根元素定义的。

You can include any other layout attributes in the <include> that are supported by the root element in the included layout and they will override those defined in the root element.

这听起来像你只能覆盖layout_ *属性。 (有人可能会被诱惑看一看源$ C ​​$ C,看看别的东西暗中支持,但是这将是一个没有没有在向前兼容性方面。)

It sounds like you can only override the layout_* attributes. (One might be tempted take a look at the source code to see if something else is secretly supported, but that would be a no-no in terms of forward compatibility.)

这篇关于如何设置被包括在另一布局的Andr​​oid布局内属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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