我需要将Spinner
中的TextInputLayout
与ConstraintLayout
进行基线对齐。这是我的xml:
<?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="match_parent"
tools:context=".MainActivity">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hint" />
</com.google.android.material.textfield.TextInputLayout>
<Spinner
android:id="@+id/spinner"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:entries="@array/spinner_values"
app:layout_constraintStart_toEndOf="@id/textInputLayout"
app:layout_constraintBaseline_toBaselineOf="@id/textInputLayout"
/>
@array/spinner_values
的值:
<string-array name="spinner_values">
<item>hello</item>
</string-array>
显然Spinner
基线与TextInputLayout
的基线不对齐。我该如何解决?
基本上TextInputLayout
不向Baseline提供其父级布局。尝试以下操作可能会对您有所帮助。