Search code examples
androidkotlinpicassocoil

Picasso and Coil inconsistency in image sizing?


The first screenshot is with Picasso, the second one with Coil (both in latest versions). Any idea why is this happening?

Picasso: fit().centerInside()

Coil: scale(Scale.FILL).crossfade(true) (I tried with FIT also, same results)

ImageView: adjustViewBounds = true; scaleType = CENTER_INSIDE with MATCH_PARENT width and constant height in pixels.

Picasso

Coil


Solution

  • Coil automatically adjusts to the scale type of the ImageView so you don't need to configure the scale.

    Picasso does not, and Picasso's .fit().centerInside() is actually not equivalent to ImageView's CENTER_INSIDE but to FIT_CENTER (it will enlarge the image so that at least one dimension matches the ImageView). There is no equivalent to CENTER_INSIDE with Picasso but these are the closest options:

    • You can simply remove .fit().centerInside() and let the ImageView scale down the image if it's larger, but if the image is very large it will consume a lot of memory (and may fail to load if larger than the max texture size of the device).
    • You can use .resize(width, height).centerInside().onlyScaleDown() after measuring the size of the ImageView manually.

    If you want Coil to resize the image the same way Picasso does with .fit().centerInside(), then just change the scale type of the ImageView to FIT_CENTER.