Fit image height and center horizontally inside CircleImageView in Android Studio

44 Views Asked by At

I have a CircleImageView (using hdodenhof's CircleImageView library here) that is 80x80 dp, and I have a Drawable image that has 2/1 aspect ratio so it's, say, 1000x500 px.

I need to fit the image so that it's height fits the ImageView, and then center it horizontally inside the ImageView, I would like to do it entirely in XML, without using Kotlin (or Java) if possible. with the following code:

<de.hdodenhof.circleimageview.CircleImageView
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/picElement"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:src="@drawable/default_element"
            android:paddingLeft="5dp" />

I have a result similar to this rapresentation:

enter image description here

But I need to have a result as the following:

enter image description here

So far, I've tried the following parameters found around the internet:

android:layout_centerHorizontal="true"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_gravity="center_horizontal"

But no success. One thing I noticed is that these parameters requires that either one of android:layout_width or android:layout_height (or both) should be equal to wrap_content, but I need the ImageView to have fixed squared size as stated above (80x80 dp).

Thank you!

0

There are 0 best solutions below