在ConstraintLayout中将TextView文本垂直对齐到TextInputLayout文本

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

ConstraintLayout中,我的TextViewTextInputLayout以下。可以轻松地看到,TextView的文本比TextInputLayout的文本更靠左。我该如何解决?

这是我当前的代码:

<?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">

<EditText
    android:id="@+id/editText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="16dp"
    android:ems="10"
    android:inputType="textPersonName"
    android:text="Name"
    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:layout_marginStart="16dp"
    android:layout_marginLeft="16dp"
    android:text="TextView"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/editText" />

这是当前结果:

设计视图:

enter image description here

蓝图:

enter image description here

仿真器:

enter image description here

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

您应该尝试将默认的paddingStart值属性从TextInputLayout放置到TextViewView,这将确保它们始终与每个设备对齐,而不必写任何常数”]

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