Android 在不切割其他视图的情况下,使视图尽可能宽

Android 在不切割其他视图的情况下,使视图尽可能宽,android,android-layout,android-constraintlayout,Android,Android Layout,Android Constraintlayout,我在约束图中有两个视图(A和B)。我想将A&B约束到父对象的左侧/起点,但我希望A尽可能宽,而不将B的一部分(应完全显示)剪切到A的右侧。如果A太宽,则应将其环绕到下一行,以便B可以完全显示。这是我到目前为止尝试过的,但A似乎采用了固定的宽度,在它和B之间留下了空白 <androidx.appcompat.widget.AppCompatTextView android:ellipsize="end" android:maxLines="2"

我在约束图中有两个视图(A和B)。我想将A&B约束到父对象的左侧/起点,但我希望A尽可能宽,而不将B的一部分(应完全显示)剪切到A的右侧。如果A太宽,则应将其环绕到下一行,以便B可以完全显示。这是我到目前为止尝试过的,但A似乎采用了固定的宽度,在它和B之间留下了空白

<androidx.appcompat.widget.AppCompatTextView
        android:ellipsize="end"
        android:maxLines="2"
        android:layout_marginEnd="10dp"
        tools:text="Iceland A text"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/b"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constrainedWidth="true"
        android:textStyle="bold"
        android:id="@+id/a"
        android:layout_width="0dp"
        android:layout_height="wrap_content"/>

<androidx.appcompat.widget.AppCompatTextView
        android:textColor="@color/tcBlack"
        tools:text="500 Items"
        android:id="@+id/b"
        android:textSize="18sp"
        android:layout_marginStart="10dp"
        app:layout_constraintStart_toEndOf="@+id/a"
        app:layout_constraintBottom_toBottomOf="@+id/a"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>



尝试以下布局:

<androidx.constraintlayout.widget.ConstraintLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is some very long text. This is some very long text. This is some very long text. This is some very long text. This is some very long text. "
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/textView2"
        app:layout_constrainedWidth="true"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/textView1"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

据我从你的问题中了解。您可以将视图B的“右”约束设置为“父视图的右”,使“宽度为包裹内容”。然后,您可以将视图A的左约束设置为父视图的左约束,将视图B的右约束设置为左约束,使宽度为match_约束。我已经尝试过了,但其外观与上面的相同。蒸馏器似乎有固定的宽度。如果你能让它工作,请与我分享你的xml,我会标记你的答案。你能分享手机/模拟器屏幕的图片吗?我想知道它看起来是什么样子。我不太明白你想要什么,你能分享一些你想要做什么的草图吗