Amrmsmb
Amrmsmb

Reputation: 11416

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

Upvotes: 0

Views: 63

Answers (3)

furkanbicak
furkanbicak

Reputation: 33

app:layout_constraintBottom_toBottomOf="parent"

Upvotes: 0

Prajwal Waingankar
Prajwal Waingankar

Reputation: 2728

Remove bottomTobottomOfParent attribute from the Edittext and it will be attached to the top of your screen.

Upvotes: 0

Wahdat Jan
Wahdat Jan

Reputation: 4156

Remove this line

app:layout_constraintBottom_toBottomOf="parent"

Upvotes: 4

Related Questions