Android ImageView ScaleTypes介绍

  

       原文地址:http://bon-app-etit.blogspot.hk/2014/01/p_w_picpathview-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>

    


     图片大于给定的空间截图:


     Android ImageView ScaleTypes介绍



     图片小于给定的空间截图:

     Android ImageView ScaleTypes介绍

   

   PS:通过对比每种ScaleType的缩放效果图,加深对ScaleType的理解。