原文地址:http://bon-app-etit.blogspot.hk/2014/01/imageview-scaletypes.html
當圖片要在應用程序上顯示的時候,我們需要關心它將以怎樣的方式進行縮放,最基本的方式是在佈局文件中的ImageView中設置正確的縮放類型(scaleType)。
Android中ImageView提供了以下不同的縮放類型:
center
centerInside
centerCrop
fitXY
fitStart
fitCenter(默認)
fitEnd
matrix(用於圖片的矩陣轉換)
下面提供設置不同的縮放類型ImageView顯示的截圖
佈局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/logo" android:scaleType="centerCrop" /> </RelativeLayout>
圖片大於給定的空間截圖:
圖片小於給定的空間截圖:
PS:通過對比每種ScaleType的縮放效果圖,加深對ScaleType的理解。