ImageView的scaleType

ImageView的scaleType的属性有好几种,分别是

matrix(默认):

不改变原图的大小,从ImageView的左上角开始绘制原图,原图超过ImageView的部分作裁剪处理。

center:

保持原图的大小,显示在ImageView的中心。当原图的size大于ImageView的size,超过部分裁剪处理。

centerCrop:

填满整个ImageView为目的,等比缩放,居中,超出裁剪,不会留空白

centerInside:

完全显示为目的,等比缩放,居中,可能有空白

fitCenter

把原图按比例扩大或缩小到ImageView的ImageView的高度,居中显示

fitEnd

把原图按比例扩大(缩小)到ImageView的高度,显示在ImageView的下部分位置

fitStart

把原图按比例扩大(缩小)到ImageView的高度,显示在ImageView的上部分位置

fitXY

把原图按照指定的大小在View中显示,拉伸显示图片,不保持原比例,填满ImageView.

示例一:fitCenter/fitStart/fitEnd/fitXY

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

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/iv11"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="fitCenter"
            android:src="@mipmap/ic_launcher" />

        <ImageView
            android:id="@+id/iv22"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="fitStart"
            android:src="@mipmap/ic_launcher" />

        <ImageView
            android:id="@+id/iv33"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="fitEnd"
            android:src="@mipmap/ic_launcher" />

        <ImageView
            android:id="@+id/iv44"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="fitXY"
            android:src="@mipmap/ic_launcher" />


    </LinearLayout>
</HorizontalScrollView>

在这里插入图片描述

示例二:fitCenter/fitStart/fitEnd/fitXY

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/iv1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="fitCenter"
            android:src="@mipmap/ic_launcher" />

        <ImageView
            android:id="@+id/iv2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="fitStart"
            android:src="@mipmap/ic_launcher" />

        <ImageView
            android:id="@+id/iv3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="fitEnd"
            android:src="@mipmap/ic_launcher" />

        <ImageView
            android:id="@+id/iv4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="fitXY"
            android:src="@mipmap/ic_launcher" />

    </LinearLayout>
</ScrollView>

在这里插入图片描述

示例三:center/centerInside/centerCrop

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/iv1"
            android:layout_width="50dp"
            android:layout_height="100dp"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="center"
            android:src="@mipmap/ic_launcher" />

        <ImageView
            android:id="@+id/iv2"
            android:layout_width="50dp"
            android:layout_height="100dp"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="centerInside"
            android:src="@mipmap/ic_launcher" />

        <ImageView
            android:id="@+id/iv3"
            android:layout_width="50dp"
            android:layout_height="100dp"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="centerCrop"
            android:src="@mipmap/ic_launcher" />

    </LinearLayout>
</ScrollView>

在这里插入图片描述

示例四:center/centerInside/centerCrop

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/iv1"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="center"
            android:src="@mipmap/ic_launcher" />

        <ImageView
            android:id="@+id/iv2"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="centerInside"
            android:src="@mipmap/ic_launcher" />

        <ImageView
            android:id="@+id/iv3"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="centerCrop"
            android:src="@mipmap/ic_launcher" />

    </LinearLayout>
</ScrollView>

在这里插入图片描述

示例五:matrix

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/iv1"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="matrix"
            android:src="@mipmap/ic_launcher" />

        <ImageView
            android:id="@+id/iv2"
            android:layout_width="50dp"
            android:layout_height="100dp"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="matrix"
            android:src="@mipmap/ic_launcher" />

        <ImageView
            android:id="@+id/iv3"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_margin="5dp"
            android:background="#ff0000"
            android:scaleType="matrix"
            android:src="@mipmap/ic_launcher" />

    </LinearLayout>
</ScrollView>

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值