Android ImageView scaleType 属性详细介绍与使用

简介: Android ImageView scaleType 属性详细介绍与使用

一、ImageViewsrc 属性与 background 的区别

  • background 通常指的都是背景,而 src 指的是内容。
  • 当使用 src 填入图片时,是按照图片大小百接填充,并不会进行拉伸,而使用 background 填入图片,则是会根据 ImageView 给定的宽度来进行拉伸。
<!-- ImageView 根据内容适应宽度 -->
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@mipmap/ic_launcher"/>
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@mipmap/ic_launcher"/>
<!-- ImageView 限制宽度 -->
<ImageView
    android:layout_width="160dp"
    android:layout_height="80dp"
    android:background="@mipmap/ic_launcher"/>
<ImageView
    android:layout_width="160dp"
    android:layout_height="80dp"
    android:src="@mipmap/ic_launcher"/>
<!-- ImageView 有图片有背景 -->
<ImageView
    android:layout_width="160dp"
    android:layout_height="80dp"
    android:background="#ffc"
    android:src="@mipmap/ic_launcher"/>

二、scaleType 属性


相关文章
|
4月前
|
XML Java Android开发
Android Studio App开发中改造已有的控件实战(包括自定义支付宝月份选择器、给翻页栏添加新属性、不滚动的列表视图 附源码)
Android Studio App开发中改造已有的控件实战(包括自定义支付宝月份选择器、给翻页栏添加新属性、不滚动的列表视图 附源码)
42 1
|
4天前
|
测试技术 Android开发 开发者
RK3568 Android系统客制化动态替换ro任意属性
RK3568 Android系统客制化动态替换ro任意属性
24 1
|
8月前
|
Android开发 UED
Android focusable属性的作用
Android focusable属性的作用
157 0
|
8月前
|
XML Android开发 数据格式
Android中利用shape属性自定义设置Button按钮
Android中利用shape属性自定义设置Button按钮
137 0
|
4月前
|
传感器 监控 物联网
Android Ble蓝牙App(三)特性和属性
Android Ble蓝牙App(三)特性和属性
|
8月前
|
Android开发
#6,Android Studio Android 开发控件 显示图片 ImageView的使用
#6,Android Studio Android 开发控件 显示图片 ImageView的使用
|
8月前
|
Android开发
Android ImageView视图的七种图片缩放类型
Android ImageView视图的七种图片缩放类型
111 0
|
8月前
|
Android开发
Android onActivityResult()的属性与用法
Android onActivityResult()的属性与用法
94 1
|
8月前
|
Android开发
Android ImageView 使用
Android ImageView 使用
61 0