What is Android ImageView ScaleType
Tags: android, java, codenewbie
Published: 2020-08-31 17:55:34

You want to use an ImageView on your App and you are wondering which ScaleType you should use. I have a good news for you, there is an App for that

&nbsp;

<img class="aligncenter size-full wp-image-709" src="http://www.offlineprogrammer.com/wp-content/uploads/2020/08/theres-an-app.jpg" alt="" width="600" height="400" />

&nbsp;

Yes I created an App that you can find <a href="https://github.com/offlineprogrammer/ScaleTypeApp">here</a> to show you all the different ScaleType values. And even further below are screenshots of all those values side by side

&nbsp;

<img class="aligncenter size-full wp-image-713" src="http://www.offlineprogrammer.com/wp-content/uploads/2020/08/Android-ImageView-ScaleType.png" alt="" width="1577" height="1814" />

&nbsp;

The full descriptions of each ScaleType from the official <a href="https://developer.android.com/reference/android/widget/ImageView.ScaleType.html">Android documentation</a>.
<h3></h3>
<h3>CENTER</h3>
&nbsp;

Center the image in the view, but perform no scaling.

<strong><code>android:scaleType="center"</code></strong>
<h3></h3>
<h3>CENTER_CROP</h3>
&nbsp;

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 larger than the corresponding dimension of the view (minus padding).

<strong><code>android:scaleType="centerCrop"</code></strong>
<h3></h3>
<h3>CENTER_INSIDE</h3>
&nbsp;

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).

<strong><code>android:scaleType="centerInside"</code></strong>
<h3></h3>
<h3>FIT_CENTER</h3>
&nbsp;

Scale the image using <a href="https://developer.android.com/reference/android/graphics/Matrix.ScaleToFit#CENTER"><strong><code>Matrix.ScaleToFit#CENTER</code></strong></a>.

<strong><code>android:scaleType="fitCenter"</code></strong>.
<h3></h3>
<h3>FIT_END</h3>
&nbsp;

Scale the image using <strong><code><a href="https://developer.android.com/reference/android/graphics/Matrix.ScaleToFit#END">Matrix.ScaleToFit#END</a></code></strong>.

<strong><code>android:scaleType="fitEnd"</code></strong>
<h3></h3>
<h3>FIT_START</h3>
&nbsp;

Scale the image using <strong><code><a href="https://developer.android.com/reference/android/graphics/Matrix.ScaleToFit#START">Matrix.ScaleToFit#START</a></code></strong>.

<strong><code>android:scaleType="fitStart"</code></strong>
<h3></h3>
<h3>FIT_XY</h3>
&nbsp;

Scale the image using <strong><code><a href="https://developer.android.com/reference/android/graphics/Matrix.ScaleToFit#FILL">Matrix.ScaleToFit#FILL</a></code></strong>.

<strong><code>android:scaleType="fitXY"</code></strong>
<h3></h3>
<h3>MATRIX</h3>
&nbsp;

Scale using the image matrix when drawing. The image matrix can be set using <strong><code><a href="https://developer.android.com/reference/android/widget/ImageView#setImageMatrix(android.graphics.Matrix">ImageView#setImageMatrix(Matrix)</a></code></strong>.

<strong><code>android:scaleType="matrix"</code></strong>

&nbsp;

Check the full code on <a href="https://github.com/offlineprogrammer/ScaleTypeApp">github</a> and follow me on <a href="https://twitter.com/MohammedMalaka">Twitter</a> for more tips about #coding, #learning, #technology, #Java, #JavaScript, #Autism, #Parenting...etc.

Check my Apps on <a href="https://bit.ly/3h05gQ7">Google Play