javaandroidimageviewandroid-xmlscaletype

How does scaleType and wrap_content determine ImageView width and height?


I'm trying to understand how layout_width/height when sets to "wrap_content", "goes" together with scaleType? AFAIK, scaleType (let's say 'center_fit') responsible of scaling up or down image size, but when width or height is set to wrap_content, isn't it means that the width & height of the ImageView will be calculated from the image (drawable) size? So why in this situation, the drawable will be scaled at all?


Solution

  • scaleType defines how you want your image to appear in the case that the width and height isn't match / appropriate e.g. fitCenter makes it centered and fit, while fitXY stretches it if it has spaces.