将视图定位在约束布局中父对象顶部的属性和值



在下面的约束布局中,我试图将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_constractBottom_toBottomOf="父";

相关内容

最新更新