Android ImageView ScaleType 图解

ImageView ScaleType

ImageView的Android:scaleType属性,是用来告诉android:src=设置的图片,如何调整去匹配ImgeView。此属性对android:background设置的背景图无效,android:background设置的图片是平铺整个ImageView。效果同android:scaleType="fitXY"

scaleType可选项:

Constant Value Description
matrix 0 左上角对齐,不缩放,显示原始大小图像
fitXY 1 让高度和宽度都与边界对齐,会改变图像的高宽比(拉伸)
fitStart 2 左上角对齐,然后等比例缩小或放大,让一边与边界对齐,另一边在边界内
fitCenter 3 居中对齐,然后等比例缩小或放大,让一边与边界对齐,另一边在边界内
fitEnd 4 右下角对齐,然后等比例缩小或放大,让一边与边界对齐,另一边在边界内
center 5 居中对齐,不缩放,显示原始图像
centerCrop 6 居中对齐,然后等比缩放,一条边与边界对齐,另一条边在边界外
centerInside 7 居中对齐,大于边界尺寸的图像会等比缩小,让一边与边界对齐,另一边在边界内。小于边界尺寸的图像直接显示

总结

Constant 不变形 居中 不超边界 缩小对齐边界 放大对齐边界
matrix        
fitXY  
fitStart  
fitCenter
fitEnd  
center      
centerCrop  
centerInside  

上效果图

matrix:左上角对齐,不缩放,显示原始大小图像 
img{20*30} 
fitXY: 拉伸 
这里写图片描述 
fitStart : 左上角对齐,然后等比例缩小或放大,让一边与边界对齐,另一边在边界内 
这里写图片描述 
fitCenter: 居中对齐,然后等比例缩小或放大,让一边与边界对齐,另一边在边界内 
这里写图片描述 
fitEnd : 右下角对齐,然后等比例缩小或放大,让一边与边界对齐,另一边在边界内 
这里写图片描述 
center : 居中对齐,不缩放,显示原始图像 
这里写图片描述 
centerCrop : 居中对齐,然后等比缩放,让一条边与边界对齐,另一条边在边界外 
这里写图片描述 
centerInside :居中对齐,大于边界尺寸的图像会等比缩小,让一边与边界对齐,另一边在边界内。小于边界尺寸的图像直接显示 
这里写图片描述

附布局文件

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:layout_width="180dp"
                android:layout_height="180dp"
                android:layout_centerInParent="true"
                android:background="@android:color/darker_gray"
                android:src="@drawable/bgbig"/>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:layout_width="180dp"
                android:layout_height="90dp"
                android:layout_centerInParent="true"
                android:layout_gravity="center_vertical"
                android:background="@android:color/darker_gray"
                android:src="@drawable/bgbig"/>
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:layout_width="180dp"
                android:layout_height="180dp"
                android:layout_centerInParent="true"
                android:background="@android:color/darker_gray"
                android:src="@drawable/bgsmall"/>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <ImageView
                android:layout_width="180dp"
                android:layout_height="90dp"
                android:layout_centerInParent="true"
                android:layout_gravity="center_vertical"
                android:background="@android:color/darker_gray"
                android:src="@drawable/bgsmall"/>
        </RelativeLayout>
    </LinearLayout>

</LinearLayout>

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77

附主题文件

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme.image" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <!-- <item name="android:scaleType">matrix</item>-->
        <!-- <item name="android:scaleType">fitXY</item>-->
        <!-- <item name="android:scaleType">fitStart</item>-->
        <!-- <item name="android:scaleType">fitCenter</item>-->
        <!-- <item name="android:scaleType">fitEnd</item>-->
        <!-- <item name="android:scaleType">center</item>-->
        <!-- <item name="android:scaleType">centerCrop</item>-->
        <item name="android:scaleType">centerInside</item>
    </style>

</resources>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

附图片文件

bgsmall.jpg 
bgsmall. 
bgbig.ipg 
这里写图片描述

转载地址:http://blog.csdn.net/u013185164/article/details/48091483

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值