基线对齐微调器到ConstraintLayout中的TextInputLayout

问题描述 投票:0回答:1

我需要将Spinner中的TextInputLayoutConstraintLayout进行基线对齐。这是我的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>

这是结果:enter image description here

显然Spinner基线与TextInputLayout的基线不对齐。我该如何解决?

android layout material-design android-constraintlayout
1个回答
1
投票

基本上TextInputLayout不向Baseline提供其父级布局。尝试以下操作可能会对您有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.