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 属性


相关文章
|
Shell API Android开发
android queries属性
android queries属性
1507 2
|
Android开发 开发者
Android自定义View之不得不知道的文件attrs.xml(自定义属性)
本文详细介绍了如何通过自定义 `attrs.xml` 文件实现 Android 自定义 View 的属性配置。以一个包含 TextView 和 ImageView 的 DemoView 为例,讲解了如何使用自定义属性动态改变文字内容和控制图片显示隐藏。同时,通过设置布尔值和点击事件,实现了图片状态的切换功能。代码中展示了如何在构造函数中解析自定义属性,并通过方法 `setSetting0n` 和 `setbackeguang` 实现功能逻辑的优化与封装。此示例帮助开发者更好地理解自定义 View 的开发流程与 attrs.xml 的实际应用。
430 2
Android自定义View之不得不知道的文件attrs.xml(自定义属性)
|
XML 前端开发 Android开发
Android:UI:Drawable:View/ImageView与Drawable
通过本文的介绍,我们详细探讨了Android中Drawable、View和ImageView的使用方法及其相互关系。Drawable作为图像和图形的抽象表示,提供了丰富的子类和自定义能力,使得开发者能够灵活地实现各种UI效果。View和ImageView则通过使用Drawable实现了各种图像和图形的显示需求。希望本文能为您在Android开发中使用Drawable提供有价值的参考和指导。
577 2
|
Java Android开发 C++
Android源代码定制:MK文件执行顺序|属性覆盖
Android源代码定制:MK文件执行顺序|属性覆盖
2043 2
Android源代码定制:MK文件执行顺序|属性覆盖
|
Java Android开发
18. 【Android教程】图片控件 ImageView
18. 【Android教程】图片控件 ImageView
679 4
|
缓存 安全 Java
Android中的persistent属性
Android中的persistent属性
1397 2
|
Java Android开发 Kotlin
Android项目架构设计问题之要在Glide库中加载网络图片到ImageView如何解决
Android项目架构设计问题之要在Glide库中加载网络图片到ImageView如何解决
280 0
|
Android开发
通过反射方式获取Android设备系统属性
通过反射方式获取Android设备系统属性 【5月更文挑战第1天】
472 2
|
Android开发
AutoX——当Android中clickable属性显示为false,实际可点击的布局如何处理
AutoX——当Android中clickable属性显示为false,实际可点击的布局如何处理
364 0
|
Android开发 C++
Android 系统属性(SystemProperties)
Android 系统属性(SystemProperties)
1256 1

热门文章

最新文章