Search code examples
androidandroid-relativelayoutandroid-constraintlayout

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


in the below constraint layout, I am trying to position the EditText at the very top not in the center of the vertical and center of the horizontal. is there any attribute with a particular value to achieve that? code:

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

Solution

  • Remove this line

    app:layout_constraintBottom_toBottomOf="parent"