Android ImageView.ScaleType详解

    联网获取到商品图片,显示时发现大小不合理,查资料发现得设置ScaleType属性:

<ImageView
            android:id="@+id/grid_item_mainpage_web_image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:src="@drawable/shop_img_default" />

public static final ImageView.ScaleType CENTER
Added in  API level 1

Center the image in the view, but perform no scaling. From XML, use this syntax: android:scaleType="center".

按图片的本来的大小居中显示,如果图片宽(高)超过View的宽(高),则截取图片的居中部分显示

public static final ImageView.ScaleType CENTER_CROP
Added in  API level 1

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). The image is then centered in the view. From XML, use this syntax: android:scaleType="centerCrop".

按比例扩大图片到宽(高)等于或大于View的宽(高),并截取图片的居中部分显示

public static final ImageView.ScaleType CENTER_INSIDE
Added in  API level 1

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). The image is then centered in the view. From XML, use this syntax: android:scaleType="centerInside".

按比例缩小图片到(高)等于或小于View的宽(高),并居中显示

public static final ImageView.ScaleType FIT_CENTER
Added in  API level 1

Scale the image using CENTER. From XML, use this syntax: android:scaleType="fitCenter".

按比例缩放图片到宽度等于View的宽度,并居中显示

public static final ImageView.ScaleType FIT_END
Added in  API level 1

Scale the image using END. From XML, use this syntax: android:scaleType="fitEnd".

按比例缩放图片到宽度等于View的宽度,并显示在View的底部

public static final ImageView.ScaleType FIT_START
Added in  API level 1

Scale the image using START. From XML, use this syntax: android:scaleType="fitStart".

按比例缩放图片到宽度等于View的宽度,并显示在View的顶部

public static final ImageView.ScaleType FIT_XY
Added in  API level 1

Scale the image using FILL. From XML, use this syntax: android:scaleType="fitXY".

不按比例缩放图片,使图片的宽高等于View的宽高,填满View

public static final ImageView.ScaleType MATRIX
Added in  API level 1

Scale using the image matrix when drawing. The image matrix can be set using setImageMatrix(Matrix). From XML, use this syntax: android:scaleType="matrix".

用矩阵来绘制图片(从左上角起),动态缩小或放大图片



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值