layout_constraintWidth_default="wrap" 已弃用任何替代方案?

Nik*_*tve 4 android android-constraintlayout

我在 textview 中使用这个 layout_constraintWidth_default="wrap" 来保持 textview 内容被包裹(在它的右边有 imageview),随着 textview 中的文本增加 textview 区域将增长,从而将 imageview 移动到右侧。

layout_constraintWidth_default="wrap"
Run Code Online (Sandbox Code Playgroud)

由于已弃用任何替代方案?

逻辑猫

在此处输入图片说明

Nik*_*tve 12

以下是我为解决方案所做的更改,imageview 不会超出可见屏幕区域:

android:layout_width="wrap_content"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="0"
app:layout_constraintHorizontal_chainStyle="packed"
Run Code Online (Sandbox Code Playgroud)
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text asdasdasdasdasdasdasdasdasdadsasdasdasdasdasdasdasd"
            app:layout_constrainedWidth="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/image"
            app:layout_constraintHorizontal_bias="0"
            app:layout_constraintHorizontal_chainStyle="packed"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/text"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)


小智 8

你可以试试这个:

\n\n
android:layout_width="wrap_content"\napp:layout_constrainedWidth="true"\n
Run Code Online (Sandbox Code Playgroud)\n\n

宽度不能为 \xe2\x80\x9c0dp\xe2\x80\x9d

\n