What's the difference between CENTER_INSIDE and FIT_CENTER scale types?

Keith picture Keith · Jul 6, 2012 · Viewed 47.3k times · Source

I can't tell the difference between ImageView.ScaleType.CENTER_INSIDE and ImageView.ScaleType.FIT_CENTER.

CENTER_INSIDE

Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).

FIT_CENTER

Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst. At least one axis (X or Y) will fit exactly. The result is centered inside dst.

Can someone illuminate the difference between the two?

Answer

Pang picture Pang · Oct 10, 2013

Here's a graphical illustration of the difference between CENTER_INSIDE and FIT_CENTER.


Image used (100 × 100):

Android_Robot_100.png


Small image view (75 × 50):

CENTER_INSIDE:

CENTER_INSIDE for small image view

FIT_CENTER:

FIT_CENTER for small image view

Both CENTER_INSIDE and FIT_CENTER shrink the image.


Large image view (300 × 200):

CENTER_INSIDE:

CENTER_INSIDE for large image view

FIT_CENTER:

FIT_CENTER for large image view

CENTER_INSIDE does not enlarge the image, FIT_CENTER does.


The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.