ImageView的scaleType属性
scaleType属性有以下值:
<code>fitCenter</code>,<code>fitStart</code>,<code>fitEnd</code>
<code>center</code>,<code>centerCrop
</code>,<code>centerInside</code>
<code>fitXY</code>,<code>matrix</code>
下文以这张650×650的图片在1080×1920的Nexus 5作示例,另外ImageView会有一个橙色的背景颜色。

xml代码大概是这个样子,就是改下ImageView的像素值和scaleType属性值,下文不再重复。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.xuhongchuan.scaletypetest.MainActivity">
<ImageView
android:src="@drawable/abc"
android:layout_width="800px"
android:layout_height="1000px"
android:layout_centerInParent="true"
android:background="@android:color/holo_orange_light"
android:scaleType="center" />
</RelativeLayout>
fitCenter
fitCenter是默认值,会对图片放大或者缩小,直到接触到ImageView的边框,例如650×650的图片在800×1000的ImageView里会放大成800×800,在400×1000的ImageView会缩小成400×400。另外会把图片居中。

fitStart和fitEnd
fitStart和fitfitEnd和fitCenter一样,只不过fitCenter是居中,而fitStart在ImageView上方,fitEnd是在下方。

center
图片保持原始大小,居中。

centerCrop
centerCrop取ImageView的宽高较大的值进行放大,如果ImageView小于图片原始大小,图片保持不变。例如650×650的图片在800×1000的ImageView中会放大为1000×1000。在400×500中保持650×650。然后居中。

centerInside
和centerCrop相反,是取ImageView的宽高较小的值进行缩小,如果ImageView大于图片原始大小,图片保持不变。例如650×650的图片在400×500的ImageView中会缩小为400×400。在800×1000中保持650×650。然后居中。

fitXY
fitXY是不管ImageView多大,图片都会进行缩放,把ImageView填满。

matrix
matrix是不管ImageView多大,图片都会保持原始大小,位于ImageView的左上角。
