Android 将文本视图文本垂直对齐到ConstraintLayout中的文本输入布局文本
在Android 将文本视图文本垂直对齐到ConstraintLayout中的文本输入布局文本,android,layout,material-design,android-constraintlayout,Android,Layout,Material Design,Android Constraintlayout,在ConstraintLayout中,我在TextInputLayout下面有一个TextView。可以很容易地看到,TextView的文本比TextInputLayout的文本从更左边开始。我怎样才能解决这个问题 这是我当前的代码: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.and
ConstraintLayout
中,我在TextInputLayout
下面有一个TextView
。可以很容易地看到,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" />
蓝图:
仿真器:
您应该尝试将默认的paddingStart值属性从文本输入布局
放到文本视图
的视图中,这将确保它们始终针对每个设备对齐,而不必写入任何常量值。您应该尝试将默认的paddingStart值属性从TextInputLayout
放到TextView
的视图中,这将确保它们始终针对每个设备对齐,而不必写入任何常量基本上LinearLayout
是TextInputLayout
的父布局,因此您可以为其指定负边距
如下
android:layout_marginLeft="-4dp"
android:layout_marginStart="-4dp"
它可以解决您的问题。基本上LinearLayout
是TextInputLayout
的父布局,因此您可以为其指定负边距
如下
android:layout_marginLeft="-4dp"
android:layout_marginStart="-4dp"
这可能会解决您的问题。不是一个解决方案,但您也可以尝试使用以下属性从编辑文本中删除paddingLeft/Start
。android:paddingStart=“0dp”
。我多次遇到这种情况,这似乎是由编辑文本的背景造成的。如果使用android:background=“@null”
删除它,您将看到文本正确对齐。不幸的是,这也会删除EditText
中的下划线。如果你不介意一个粗俗的黑客攻击,你总是可以从EditText
上的android:marginlet
中删除3dp-这似乎也能奏效。试试android:layout\u marginLeft=“-4dp”TextInputLayout或EditText?你检查过我的答案吗?这不是一个解决方案,但你也可以尝试使用以下属性从编辑文本中删除paddingLeft/Start
。我已经多次遇到这个问题,这似乎是由EditText
的背景造成的。如果使用android:background=“@null”
删除它,您将看到文本正确对齐。不幸的是,这也会删除EditText
中的下划线。如果你不介意一个粗俗的黑客攻击,你总是可以从EditText
上的android:margintart
中删除3dp-这似乎也能奏效。试试android:layout\u marginLeft=“-4dp”TextInputLayout或EditText?你检查过我的答案了吗?