Search code examples
javaandroidxmlandroid-imageview

Android studio XML centercrop doesn't center the image


bouclier.jpg

I have added a background-image in Android Studio, I used center-crop to center it.

The problem I have is that the image does not center properly. it's slightly off to the right and I want it perfectly centered

Look on the right the stars are not well centered.

Here's what I have tried

Layout

Could you help me ?

Thank you.


Solution

  • Thanks for updating your question with the background image (bouclier.jpg) that you're using. The issue you're experiencing is not to do with your layout (XML) code, but rather with the image itself.

    Your background image is offset to the right ever so slightly

    As you can see, your background image appears to be offset to the right ever so slightly (I've added a green cross in the above image to illustrate this). As a result, when you use android:scaleType="centerCrop" the image is correctly centred but doesn't look right.

    My recommendation would be to choose a different (properly centred) image to use as your background, or alternatively to centre the image you're presently using.

    I hope that helps!