android layout xml镶嵌,Android XML Layout的'include'标签真的有用吗?

我刚刚发现了这个问题。 首先,您只能覆盖layout_ *属性,因此后台将不起作用。 这是记录在案的行为,只是我的疏忽。

真正的问题在LayoutInflater.java中找到:

// We try to load the layout params set in the tag. If

// they don't exist, we will rely on the layout params set in the

// included XML file.

// During a layoutparams generation, a runtime exception is thrown

// if either layout_width or layout_height is missing. We catch

// this exception and set localParams accordingly: true means we

// successfully loaded layout params from the tag,

// false means we need to rely on the included layout params.

ViewGroup.LayoutParams params = null;

try {

params = group.generateLayoutParams(attrs);

} catch (RuntimeException e) {

params = group.generateLayoutParams(childAttrs);

} finally {

if (params != null) {

view.setLayoutParams(params);

}

}

如果标记不包含layout_width和layout_height,则会发生RuntimeException并以静默方式处理,甚至没有任何日志语句。

解决方案是在使用标记时始终包含layout_width和layout_height,如果要覆盖任何layout_ *属性。

我的例子应该改为:

android:id="@+id/buttons_override"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

layout="@layout/buttons"/>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值