Android ConstraintLayout TextView 溢出

Android ConstraintLayout TextView is overflow

我正在开发 Android 应用程序。

我正在尝试像下面聊天那样发展 ui。

短消息:

长消息:

但这并不容易..; 这是我的代码。 它正确显示了长消息。

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingStart="12dp"
    android:paddingEnd="28dp">

    <ImageView
        android:id="@+id/iv_profile"
        android:layout_width="32dp"
        android:layout_height="32dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/tv_profile_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:maxLines="1"
        android:textColor="@color/gray_90"
        android:textSize="12sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@id/iv_profile"
        app:layout_constraintTop_toTopOf="@id/iv_profile"
        tools:text="User Nickname1" />

    <TextView
        android:id="@+id/tv_message"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:background="@drawable/rect_corner22_gray10"
        android:paddingStart="16dp"
        android:paddingTop="11dp"
        android:paddingEnd="16dp"
        android:paddingBottom="11dp"
        android:textColor="@color/gray_90"
        app:layout_constraintStart_toStartOf="@id/tv_profile_name"
        app:layout_constraintEnd_toStartOf="@id/tv_time"
        app:layout_constraintTop_toBottomOf="@id/tv_profile_name"
        tools:text="Blah Blah Blah
Blah Blah Blah Blah Blah Blah
Blah Blah
 Blah Blah Blah Blah
Blah Blah
Blah Blah Blah Blah Blah Blah
" />

    <TextView
        android:id="@+id/tv_time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginStart="4dp"
        android:textColor="@color/gray_60"
        android:textSize="10sp"
        app:layout_constraintBottom_toBottomOf="@id/tv_message"
        app:layout_constraintStart_toEndOf="@id/tv_message"
        app:layout_constraintEnd_toEndOf="parent"
        tools:text="02/20 4:46 PM" />

</androidx.constraintlayout.widget.ConstraintLayout>

但是如果我设置短文本,那么它显示如下:

我该如何解决这个问题?

解决方法是:app:layout_constrainedWidth="true"

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#FFFFFF">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#00F"
    android:padding="10dp"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#EEE"
        tools:text="Lorem Ipsum"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_weight="0"
        android:background="#EEE"
        tools:text="01/20 4:46 PM"/>

</LinearLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="#00F"
    android:padding="10dp"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#EEE"
        tools:text="Lorem Ipsum is simply dummy text of the
         printing and typesetting industry. Lorem
        Ipsum has been the industry's standard
         dummy text ever since the 1500s"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_weight="0"
        android:background="#EEE"
        tools:text="02/20 4:46 PM"/>

</LinearLayout>