首页 > 解决方案 > ConstraintLayout 用 app:layout_constrainedHeight="true" 隐藏 TextView 的最后一行

问题描述

我注意到ConstraintLayout(版本 1.1.3)的奇怪行为,TextView每当我尝试使用带wrap_content属性的高度并layout_constrainedHeight设置为true.

layout_constrainedHeight

第一张图片

没有layout_constrainedHeight

第二张图片

源代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:text="Lorem..."
        app:layout_constrainedHeight="true"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

我认为每当我想使用wrap_contentwith时,ConstraintLayout我都必须设置layout_constrainedHeight为 true,但这有时会给我带来奇怪的错误。我错过了什么吗?

编辑

如果我删除周围的边距TextView,它可以正常工作。似乎这ConstraintLayoutwrap_content和边距方面有问题。

标签: androidandroid-constraintlayoutandroid-jetpack

解决方案



推荐阅读