ImageView中scaleType参数配图详细说明

一、已经很久没有写博客了,有一些基本的常识没有搞清楚,这次使用代码亲自测试一把,首先来两张图片,一张小图分辨率为494x212;一张大图,分辨率为3840x2400。



二、再贴一下基本的xml代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/iv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:scaleType="fitXY"
        android:src="@drawable/hhhhh" />
</RelativeLayout>

三、测试

1、android:scaleType="center"

说明:当图片长/宽小于View的长/宽,按图片的原来size居中显示;当图片长/宽超过View的长/宽,则截取图片的居中部分显示。
测试图片:

2、
android:scaleType="centerCrop"
按比例扩大图片的size居中显示,使得图片长(宽)等于或大于View的长(宽)


3、
android:scaleType="centerInside"
将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于View的长/宽。

4、
android:scaleType="fitCenter"
把图片按比例扩大/缩小到View的宽度,居中显示,一般手机相册使用这种方式。


5、
android:scaleType="fitStart"

6、
android:scaleType="fitEnd"

7、
android:scaleType="fitXY"
不按比例缩放图片,目标是把图片塞满整个View





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值