我刚刚发现了这个问题。 首先,您只能覆盖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"/>