嵌套约束布局忽略外部约束

3

目前我正在尝试嵌套两个Constraint Layouts。为此,我使用了<include/> 标签。但我发现内部的Constraint Layout忽略外部Constraint Layout的所有约束条件。为了更好地说明这一点,我在内部的Constraint Layout周围绘制了一个边框:

enter image description here

我使用的是com.android.support.constraint:constraint-layout:1.0.0-alpha3进行测试。

我的问题是:我做错了什么?还是这个alpha版本中存在一个bug?

2个回答

5
为了使用<include/>标签向包含的布局添加属性,你必须在标签本身中指定宽度和高度,覆盖或仅仅确认包含布局的根标签的宽度和高度。

例如:

<include
    layout="@layout/item_place_custom"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent" />

这将导致包含的布局按预期被约束在其父布局的底部。这不仅适用于较新的ConstraintLayout,也适用于<include/>标记,如此处所述。

-1
在我的情况下,内部的<include>布局已经合并为父级。我将其更改为Framelayout,问题得到了解决!

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接