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

标签 android android-layout android-constraintlayout

目前我正在尝试将两个约束布局相互嵌套。为此,我使用 <include/>标签。我看到的是内部约束布局忽略了外部约束布局的所有约束。为了使它更明显,我在内部约束布局周围画了一个边框:

enter image description here

为了尝试这些东西,我使用了 com.android.support.constraint:constraint-layout:1.0.0-alpha3 .

我现在的问题是:我是不是做错了什么,或者它甚至是 alpha 版本的错误?

最佳答案

为了使用 <include/> 将属性添加到包含的布局中标签,您必须在标签本身中同时指定宽度和高度,以覆盖或简单地确认所包含布局的根标签的宽度和高度。

例子:

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

这会导致包含的布局按预期被限制在其父布局的底部。

这不是较新的 ConstraintLayout 独有的,这是 <include/> 的预期行为标记为 here

关于android - 嵌套约束布局忽略外部约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38143776/

相关文章:

android - Firemonkey Android 访问日历和 Activity

java - 将购买的商品详细信息发送至 PayPal?

android - 如何在没有代码的情况下隐藏 Android 布局 xml 中的部分可见 View ?

java - 将 ListView 添加到 fragment 会缩小布局

Android相对布局定位

android - 约束布局 : Create a button that fills space after a RecyclerView

android - 在 Android 的 Scrollview 中使用约束布局是个好主意吗?

安卓。将文件保存到设备上的共享目录中

android - XML Spinner 属性 textAlignment = "right"API 16

android - 如何使我的 TextView 包装内容并遵守最大宽度