注意

  请查看本文后期更新完整版:

  http://www.cnblogs.com/over140/archive/2011/06/08/2075054.html

声明

  欢迎转载,但请保留文章原始出处:)

    博客园:http://www.cnblogs.com

    农民伯伯: http://www.cnblogs.com/over140/

正文

  一、结构

    java.lang.Object

      android.view.View

        android.widget.ImageView

    已知直接子类:

    ImageButton, QuickContactBadge

    已知间接子类:

    ZoomButton

  二、类概述

    显示任意图像,例如图标。ImageView类可以加载各种来源的图片(如资源或图片库),需要计算图像的尺寸,比便它可以在其他布局中使用,并提供例如缩放和着色(渲染)各种显示选项。

  三、XML属性

属性名称

描述

android:adjustViewBounds

是否保持宽高比。需要与maxWidth、MaxHeight一起使用,否则单独使用没有效果。

android:cropToPadding

是否截取指定区域用空白代替。单独设置无效果,需要与scrollY一起使用,效果如下,实现代码见代码部分:

android:maxHeight

设置View的最大高度,单独使用无效,需要与setAdjustViewBounds一起使用。如果想设置图片固定大小,又想保持图片宽高比,需要如下设置:

1) 设置setAdjustViewBounds为true;

2) 设置maxWidth、MaxHeight;

3) 设置设置layout_width和layout_height为wrap_content。

android:maxWidth

设置View的最大宽度。同上。

android:scaleType

设置图片的填充方式。

matrix

0

用矩阵来绘图

fitXY

1

拉伸图片(不按比例)以填充View的宽高

layout_

height

:30px

layout_

width

:120px

fitStart

2

按比例拉伸图片,拉伸后图片的高度为View的高度,且显示在View的左边

fitCenter

3

按比例拉伸图片,拉伸后图片的高度为View的高度,且显示在View的中间

fitEnd

4

按比例拉伸图片,拉伸后图片的高度为View的高度,且显示在View的右边

center

5

按原图大小显示图片,但图片宽高大于View的宽高时,截图图片中间部分显示

layout_

height

:60px

layout_

width

:80px

padding

:10px

centerCrop

6

按比例放大原图直至等于某边View的宽高显示。

centerInside

7

当原图宽高或等于View的宽高时,按原图大小居中显示;反之将原图缩放至View的宽高居中显示。

android:src

设置View的drawable(如图片,也可以是颜色,但是需要指定View的大小)

android:tint

将图片渲染成指定的颜色。见下图:

左边为原图,右边为设置后的效果,见后面代码。

  四、代码  

    4.1  android:tint

<ImageView android:background="@android:color/white" android:src="@drawable/btn_mode_switch_bg"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
    <ImageView android:layout_marginLeft="5dp" android:background="@android:color/white" android:tint="#ffff00" android:src="@drawable/btn_mode_switch_bg"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>

    4.2  android:cropToPadding

<ImageView android:background="@android:color/white" android:scrollY="-10px" android:cropToPadding="true" android:src="@drawable/btn_mode_switch_bg"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
    <ImageView android:background="@android:color/white" android:scrollY="10px" android:cropToPadding="true" android:src="@drawable/btn_mode_switch_bg"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
    <ImageView android:paddingTop="10px"  android:background="@android:color/white" android:scrollY="10px" android:cropToPadding="true" android:src="@drawable/btn_mode_switch_bg"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
    <ImageView android:paddingTop="10px" android:background="@android:color/white" android:scrollY="10px" android:cropToPadding="false" android:src="@drawable/btn_mode_switch_bg"
        android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>

  五、 系列

    Android2.2 API 中文文档系列(1) —— TextView

    Android2.2 API 中文文档系列(2) —— EditText

    Android2.2 API 中文文档系列(3) —— AccessibilityService

    Android2.2 API 中文文档系列(4) —— Manifest

    Android2.2 API 中文文档系列(5) —— View

结束

  本文android:tint属性比较有意思,而android:adjustViewBounds与android:cropToPadding是难点,都花了超过一个小时才试出效果。

转载于:https://www.cnblogs.com/over140/archive/2010/09/19/1830703.html

Android2.2 API 中文文档系列(6) —— ImageView相关推荐

  1. Android2.2 API 中文文档系列(7) —— ImageButton

    前言 第七篇关于ImageButton的翻译在翻译工具帮助下独立完成,加了一些自己的理解甚至截图,水平有限,欢迎指正.欢迎更多译者一起参与Android API 的中文翻译行动!我的邮箱over140 ...

  2. Android2.2 API 中文文档系列(3) —— AccessibilityService

    前言 关键字: Android API 中文,Android SDK 中文,Android AccessibilityService 详解 本章翻译来自 java_cofi ,他的博客地址:http: ...

  3. Android2.2 r1 API 中文文档系列(10) —— CheckBox

    前言 从本章开始,将直接翻译最新的Android 2.2 r1 版本的API,而之前的文章以后更新.补充.完善至新版.本章android.widget.CheckBox内容不多,目前翻译的选择策略是先 ...

  4. Android 2.2 r1 API 中文文档系列(11) —— RadioButton

    一.结构 public class RadioButton extends CompoundButton java.lang.Object    android.view.View          ...

  5. Android 2.2 r1 API 中文文档系列(12) —— Button

    前言 截止到这篇,总共翻译了Android API十二篇,其中有两篇是翻译组另外一名成员提供.翻译工作量虽大.虽难,但不管是对自己还是对别人都是巨大的帮助,少则一篇不嫌少,多则十篇不嫌多,再次呼吁大家 ...

  6. Android2.2 API 中文文档

    http://www.cnblogs.com/over140/

  7. Android 3.0 r1 API中文文档(107) —— AsyncPlayer

    一.结构 public class AsyncPlayer extends Object java.lang.Object android.media.AsyncPlayer 二.概述 播放一个连续( ...

  8. Android API中文文档(111) —— MailTo

    一.结构 public class MailTo extends Object java.lang.Object android.net.MailTo 二.类概述 MailTo URL解析器.这个类解 ...

  9. jQuery EasyUI API 中文文档 - ValidateBox验证框

    jQuery EasyUI API 中文文档 - ValidateBox验证框,使用jQuery EasyUI的朋友可以参考下. 用 $.fn.validatebox.defaults 重写了 def ...

最新文章

  1. shell 跟踪命令
  2. 虚拟化正是云计算所依托的基石
  3. Win10专业版系统PyCharm专业版使用WSL(ubuntu20.04 LTS)配置Docker解释器配置环境详细教程
  4. php4.3.x 5.2.x,XDEBUG for PHP 5.3.0
  5. shell分割参数为数组并循环执行jar,异常时退出循环
  6. cms文章 mysql存储,帝国CMS万能标签调用随机文章的方法
  7. DFS HDOJ 2181 哈密顿绕行世界问题
  8. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_09 序列化流_2_对象的序列化流_ObjectOutputStream...
  9. 一个SQL SERVER查询分析器非常好用的工具
  10. Flexsim国外视频教程
  11. SpringSecurity 退出登录
  12. 高速公路ETC自由流收费技术
  13. 数据库的查询、视图和游标
  14. 表格说超链接危害计算机怎么办,win10系统excel表格中的超链接打不开提示“由于本机限制”的处理教程...
  15. C. Annoying Present(思维+数学)
  16. 待办事项 数据库表设计
  17. 在C语言中使用二分法算法思想解决猜商品价格问题
  18. 面向对象:怪蜀黍PK奥特曼
  19. 四样融合!对东软刘积仁的战略布局,大写的服!
  20. 每日一道leetcode(python)46. 全排列

热门文章

  1. Xamarin.Form的Android SDK工具下载安装
  2. java 正则 捕获_Java通过正则表达式捕获组中的文本
  3. 希捷硬盘固件修复工具_电脑升级高速硬盘后的差异竟如此大!酷鱼510性能实测...
  4. ifconfig 安装_第一章Linux服务器环境搭建之JDK安装
  5. mysql olap 工具_OLAP分析工具之Presto
  6. python socket发送组播数据_python3通过udp实现组播数据的发送和接收操作
  7. 微秒时间_揭秘奇特光速原子研究,记录有史以来最短时间段
  8. linux kvm百度云,如何在 Ubuntu Linux 上使用 KVM 云镜像
  9. 第九届国际冬季脑机接口会议(BCI2021)
  10. Deepfake这次不换脸了,直接换了座城市