Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I place a view to a particular offset from another view in constrainlayout

this picture

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>
like image 292
Ashutosh Avatar asked Dec 21 '25 15:12

Ashutosh


1 Answers

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.

like image 104
Cheticamp Avatar answered Dec 24 '25 04:12

Cheticamp