
SO, I have two images. one(small) image has to be in the middle to the bottom axis of the second image(smaller), but should be slightly offset from the Y axis. I was trying to do this in constraint layout. I know to set the top and bottom constraint of smaller image to the bottom of the bigger image. How can I achieve this in constraint layout? edit 1 How can i bring the beauty and the beast photo in the above link a litle down to Y axis
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="@+id/singapore"
android:scaleType="centerCrop"
android:layout_width="240dp"
android:layout_height="240dp"
android:src="@drawable/singapore"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</ImageView>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/poster"
app:layout_constraintBottom_toBottomOf="@id/singapore"
app:layout_constraintEnd_toEndOf="@id/singapore"
app:layout_constraintStart_toStartOf="@+id/singapore"
app:layout_constraintTop_toBottomOf="@id/singapore">
</ImageView>
</androidx.constraintlayout.widget.ConstraintLayout>
Setting the top and bottom of the smaller image to the bottom of the larger image vertically centers the smaller image to the bottom edge of the larger image. You can now shift the smaller image down by, say 10dp, by specifying a translation for the smaller image:
android:translationY="10dp"
See the description of the y translation property in the View documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With