Reputation: 5
i looking to align to the top of screen a simple image with ConstraintLayout. I just tried:
<ImageView
android:id="@+id/imagecookie"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/before_cookie"
app:layout_constraintTop_toBottomOf="parent" />
The pict is positionning in the middle of screen. Any help? Thanks
Upvotes: 0
Views: 66
Reputation: 74
You're setting the top of your ImageView
to the bottom
of the parent (ConstraintLayout), you need to set it to the top
EDIT Sample with the whole layout
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="@color/colorPrimary"
tools:context=".MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Result
Upvotes: 2
Reputation: 5
Thank for you time and help but it still not positioned at the top of screen. i put my picture at the top of the screen (and middle horizontal) with:
<ImageView
android:id="@+id/imagecookie"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/suzuki"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Upvotes: 0