According to Coil
s docs, I don't have to make any configuration for my image to fit()
. The problem is, that the ImageView
is not loading correctly:
This is my configuration for the ImageView
with Picasso
:
picasso.load(unsplashResult?.photoUrls?.thumbnailUrl)
.fit()
.error(R.drawable.img_placeholder)
.placeholder(R.drawable.img_placeholder)
.into(currentImageView)
And this is the code with Coil
:
currentImageView.load(unsplashResult?.photoUrls?.thumbnailUrl) {
placeholder(R.drawable.img_placeholder)
error(R.drawable.img_placeholder)
}
The result on my ImageView
is not the same though.
This is how Coil
loads them:
And this is how Picasso
loads them:
Question is, how can I achieve the same result with Coil
?
EDIT
This is my ImageView
:
<ImageView
android:adjustViewBounds="true"
android:id="@+id/ivUnsplashImage"
android:src="@drawable/some_unsplash_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:adjustViewBounds—If set to true, the attribute adjusts the bounds of the ImageView control to maintain the aspect ratio of the image displayed through it. android:resizeMode—The resizeMode attribute is used to make a control resizable so we can resize it horizontally, vertically, or around both axes.
Based on this document
You can work around this by setting the scaleType to centerCrop or scale(Scale.FILL) on your request.
https://coil-kt.github.io/coil/api/coil-base/coil.request/-request-builder/scale/
https://coil-kt.github.io/coil/api/coil-base/coil.size/-scale/
you are set Scale
type this way
view.load(chatMessageBean.thumb) {
crossfade(750)
placeholder(errorPlaceHolder)
transformations(CircleCropTransformation())
error(errorPlaceHolder)
scale(Scale.FILL)
}
So, according to migration guide answer should be like;
imageView.scaleType = ImageView.ScaleType.FIT_CENTER
or it should be defined in XML
android:scaleType="fitCenter"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With