在约束布局中将视图定位在父级顶部的什么属性和值

What attribute and which value to position a view at the top of the parent in a constraint layout

在下面的约束布局中,我试图将 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 属性,它将附加到屏幕顶部。

应用程序:layout_constraintBottom_toBottomOf="parent"