I have this XML:
<de.hdodenhof.circleimageview.CircleImageView
android:src="@drawable/ic_kitty_superhero"
android:id="@+id/userAvatar"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:layout_marginBottom="16dp"
app:civ_border_color="@android:color/white" // just to show you wrong result
app:civ_border_width="1dp" />
and this extension function to load image:
fun ImageView.loadImage(context: Context, url: String) {
val resourceID = context.resources.getIdentifier(url, "drawable", context.packageName)
if (resourceID != 0) { // if it's an image from drawable folder
Glide.with(context)
.load(resourceID)
.fitCenter()
.into(this)
} else {
Picasso.with(context)
.load(url)
.fit()
.centerInside()
.into(this)
}
}
Since Picasso doesn't know how to work with resourceID
, I need to use Glide or something similar like this.setImageResource()
. But it's cannot execute transformation that I want.
In the first photo, everything looks the way I want, but it’s just used ImageView container.
In the second photo I use CircleImageView container and it no longer looks the way I would like - the ears are cropped in the photo.
Please, can you help me, how can I get the correct result?
NOTE: I can't use .load(R.drawable.icon)
and I can't use the ImageView container (I can probably if make it circle somehow)
I solved my problem by using ImageView container and Circle Transformation for Picasso