问题描述
在下面的约束布局中,我试图将EditText放置在最顶部,而不是垂直中心和水平中心。 是否有任何具有特定价值的属性可以实现这一目标? 代码:
<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/etUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint=" "
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
解决方法
删除此行
app:layout_constraintBottom_toBottomOf="parent"
,
从Edittext中删除bottomTobottomOfParent属性,该属性将附加到屏幕顶部。
,app:layout_constraintBottom_toBottomOf =“父母”