避免重叠 Android 约束布局

Avoid overlap Android Constraint Layout

我想避免将“状态”写成两行,我正在使用约束布局。我看了其他类似的问题,但没有找到解决问题的方法。

这是我的代码:

<?xml version="1.0" encoding="utf-8"?><!--
  As recommended by Google, we use a ConstraintLayout
  as the root element
  We add a padding all around using the padding attribute
-->
<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="match_parent"
    android:padding="20dp"
    >

    <!--
    * We use the hint attribute to display the "type" string
    * The type string has been extracted into a dedicated file
    * The width is "0dp" because the "match_parent" value cannot be
    used with the constraintLayout
    * We use the inputType attribute to display the best keyboard
    to the user
    *
    -->

    <TextView
        android:id="@+id/status_label"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@id/price"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toStartOf="@id/status"
        android:text="Status :"
        android:textStyle=""
        android:textSize="18sp"
        />

    <Spinner
        android:id="@+id/status"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toEndOf="@id/status_label"
        app:layout_constraintTop_toTopOf="@id/status_label"
        />

</androidx.constraintlayout.widget.ConstraintLayout>

视图如下: View

希望您能提供一些解决方案。

<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="match_parent"
android:padding="20dp"
>

<!--
* We use the hint attribute to display the "type" string
* The type string has been extracted into a dedicated file
* The width is "0dp" because the "match_parent" value cannot be
used with the constraintLayout
* We use the inputType attribute to display the best keyboard
to the user
*
-->

<TextView
    android:id="@+id/status_label"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
  
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintEnd_toStartOf="@id/status"
    android:text="Status :"
    android:textStyle=""
    android:textSize="18sp"
    />

<Spinner
    android:id="@+id/status"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintStart_toEndOf="@id/status_label"
    app:layout_constraintTop_toBottomOf="@id/status_label"
    />

这里

可以将status_label的宽度设为wrap_content