9

According to Coils 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:

enter image description here

And this is how Picasso loads them:

enter image description here

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"/>
coroutineDispatcher
  • 7,718
  • 6
  • 30
  • 58

4 Answers4

8

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)
}
Mayur Patel
  • 2,300
  • 11
  • 30
2

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"
Ferhat Ergün
  • 135
  • 1
  • 10
1

As much I understood from the documentation you should use ImageView.ScaleType

imageView.scaleType = ImageView.ScaleType.FIT_XY

or you can use it into your xml tag of your ImageView

android:scaleType="fitXY"

Apart from FIT_XY you can use ImageView.ScaleType.CENTER_CROP too according to your needs.

RatneZ
  • 1,078
  • 9
  • 9
0

Just remove the line android:adjustViewBounds="true" in your layout XML file.

Robert Columbia
  • 6,313
  • 15
  • 32
  • 40