sir-haver
sir-haver

Reputation: 3592

How to change the absolute position of a constrained button

I have an image and on top of it (bottom-right) placed a button which is constrained to the right and bottom of the image. I would like to move the button 5dp to the right and bottom, so it sits a bit off, outside of the contours of the image.

Screenshot of the current layout, where the X button is placed within the contours:

enter image description here

XML of the button (inside a constraint layout):

<Button
    android:id="@+id/deletePic1"
    android:layout_width="@dimen/delete_picture_button_size"
    android:layout_height="@dimen/delete_picture_button_size"
    android:background="@drawable/delete_button"
    app:layout_constraintBottom_toBottomOf="@+id/profilePic1"
    app:layout_constraintEnd_toEndOf="@+id/profilePic1"
    />

Upvotes: 0

Views: 219

Answers (2)

romaing
romaing

Reputation: 38

You can use android:translationX and android:translationY

<Button
    android:id="@+id/deletePic1"
    android:layout_width="@dimen/delete_picture_button_size"
    android:layout_height="@dimen/delete_picture_button_size"
    android:background="@drawable/delete_button"
    android:translationX="5dp"
    android:translationY="5dp"
    app:layout_constraintBottom_toBottomOf="@+id/profilePic1"
    app:layout_constraintEnd_toEndOf="@+id/profilePic1"
/>

Upvotes: 1

adi purnama
adi purnama

Reputation: 156

try add

app:layout_constraintTop_toBottomOf="@+id/profilePic1"
app:layout_constraintStart_toEndOf="@+id/profilePic1"

this is not 5dp, but it sits a bit off, outside of the contours of the image

Upvotes: 1

Related Questions