ConstraintLayout 内の Wrap_content ビューが画面外に伸びる 質問する

ConstraintLayout 内の Wrap_content ビューが画面外に伸びる 質問する

を使用して簡単なチャット バブルを実装しようとしていますConstraintLayout。私が実現しようとしているのは次のことです。

ここに画像の説明を入力してください ここに画像の説明を入力してください

しかし、wrap_content私の望みどおりにはいきません。余白は尊重されますが、ビューの境界外に拡張されます。これが私のレイアウトです:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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">

    <TextView
        android:id="@+id/chat_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="16dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintHorizontal_bias="0"
        tools:background="@drawable/chat_message_bubble"
        tools:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris sodales accumsan tortor at bibendum."
        android:layout_marginStart="64dp"
        android:layout_marginLeft="64dp"
        android:layout_marginEnd="32dp"
        android:layout_marginRight="32dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp" />
</android.support.constraint.ConstraintLayout>

これは次のようにレンダリングされます。

ここに画像の説明を入力してください

使っていますcom.android.support.constraint:constraint-layout:1.0.0-beta4

何か間違ったことをしているのでしょうか? これはバグですか、それとも単に直感に反する動作ですか? を使用して適切な動作を実現できますかConstraintLayout(他のレイアウトを使用できることはわかっていますが、具体的に質問していますConstrainLayout)。

ベストアンサー1

更新 (ConstraintLayout 1.1.+)

app:layout_constrainedWidth="true"一緒に使うandroid:layout_width="wrap_content"

以前(非推奨):

app:layout_constraintWidth_default="wrap"android:layout_width="0dp"

おすすめ記事