Android2.2 API —— ImageView
注意
请查看本文后期更新完整版:
http://www.cnblogs.com/over140/archive/2011/06/08/2075054.html
来源: 农民伯伯: http://www.cnblogs.com/over140/
正文
一、结构
java.lang.Object
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 |
设置图片的填充方式。
|
|||||||||||||||||||||||||||
|
android:src |
设置View的drawable(如图片,也可以是颜色,但是需要指定View的大小) |
|||||||||||||||||||||||||||
|
android:tint |
将图片渲染成指定的颜色。见下图:
|
四、代码
4.1 android:tint
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:src="@drawable/btn_mode_switch_bg" >
</ImageView> <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:src="@drawable/btn_mode_switch_bg"
android:tint="#ffff00" >
</ImageView>
4.2 android:cropToPadding
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:cropToPadding="true"
android:scrollY="-10px"
android:src="@drawable/btn_mode_switch_bg" >
</ImageView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:cropToPadding="true"
android:scrollY="10px"
android:src="@drawable/btn_mode_switch_bg" >
</ImageView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:cropToPadding="true"
android:paddingTop="10px"
android:scrollY="10px"
android:src="@drawable/btn_mode_switch_bg" >
</ImageView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:cropToPadding="false"
android:paddingTop="10px"
android:scrollY="10px"
android:src="@drawable/btn_mode_switch_bg" >
</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是难点,都花了超过一个小时才试出效果。
Android2.2 API —— ImageView的更多相关文章
- Android2.2 API中文文档——View
概述 java.lang.Object ↳ android.view.View 已知直接子类: AnalogClock, ImageView, KeyboardView, Progres ...
- Android Camera Api的心得
(一) 前言最近看Camera的api,觉得写的真的不错.现在翻译过来,给大家分享分享,译文可能不太好,大家将就着看哈. (二) 正文1. CameraCamera是Android framework ...
- Android学习笔记-ImageView(图像视图)
本节引言: 本节介绍的UI基础控件是:ImageView(图像视图),见名知意,就是用来显示图像的一个View或者说控件! 官方API:ImageView;本节讲解的内容如下: ImageView的s ...
- 【转】GitHub 排名前 100 的安卓、iOS项目简介
GitHub Android Libraries Top 100 简介 排名完全是根据 GitHub 搜索 Java 语言选择 (Best Match) 得到的结果, 然后过滤了跟 Android 不 ...
- Android开发自学笔记(Android Studio)—4.3ImageView及其子类
一.引言 ImageView继承自View组件,主要功能用来显示图片,实际上他能显示的不仅是图片,Drawable对象都可以用ImageView来显示. ImageView派生了ImageButton ...
- Android图片加载库的理解
前言 这是“基础自测”系列的第三篇文章,以Android开发需要熟悉的20个技术点为切入点,本篇重点讲讲Android中的ImageLoader这个库的一些理解,在Android上最让人头疼是 ...
- GitHub Android Libraries Top 100 简介
本项目主要对目前 GitHub 上排名前 100 的 Android 开源库进行简单的介绍, 至于排名完全是根据 GitHub 搜索 Java 语言选择 (Best Match) 得到的结果, 然后过 ...
- 2016年GitHub 排名前 100 的安卓、iOS项目简介(收藏)
排名完全是根据 GitHub 搜索 Java 语言选择 (Best Match) 得到的结果, 然后过滤了跟 Android 不相关的项目, 所以排名并不具备任何官方效力, 仅供参考学习, 方便初学者 ...
- 64.GitHub 排名前100的android项目简介
GitHub Android Libraries Top 100 简介 排名完全是根据 GitHub 搜索 Java 语言选择 (Best Match) 得到的结果, 然后过滤了跟 Android 不 ...
随机推荐
- Object类中getClass()
Object类中包含一个方法名叫getClass,利用这个方法就可以获得一个实例的类型类.类型类指的是代表一个类型的类,因为一切皆是对象,类型也不例外,在Java使用类型类来表示一个类型.所有的类型类 ...
- cocos2d-x 3.0正式版 环境搭建 (解决载入失败,未能载入XXX包)
cocos2d-x 3.0正式版最终公布了~ 等了好久~ 废话不多说,直接写方法. 1.下载安装vc2012 ,我用的是旗舰版,传送门:点击打开链接 2.下载cocos2d-x 3.0正式版,传送门: ...
- FastDFS 的部署、配置与测试的
部署篇:http://soartju.iteye.com/blog/803477 配置篇:http://soartju.iteye.com/blog/803524 测试篇:http://soartju ...
- Linux下查看系统配置
CPU 1. lscpu:显示cpu架构信息 [xxx@localhost ~]$ lscpu Architecture: x86_64 CPU op-mode(s): -bit, -bit Byte ...
- Android开发之使用活动显示对话框
利用活动显示对话框,需要重写Activity中的onCreateDialog()方法,以此来显示一个对话框窗口. 效果如下: 实现代码如下: package com.example.dialog; i ...
- CentOS 6.7 安装配置BT下载工具Transmission
1.配置额外yum源 i386 cd /etc/yum.repos.d/ wget http://geekery.altervista.org/geekery-el6-i686.repo x86_64 ...
- 在DropDownList里显示多级分类
protected void ddlBind() { DataTable dt = new DataTable(); ddlCategoryId.DataSource = getList(" ...
- LCA问题
基本概念 LCA:树上的最近公共祖先,对于有根树T的两个结点u.v,最近公共祖先LCA(T,u,v)表示一个结点x,满足x是u.v的祖先且x的深度尽可能大. RMQ:区间最小值查询问题.对于长度为n的 ...
- Oracle 特殊字符模糊查询的方法
最近在写DAO层的时候,遇到一个问题,就是使用like进行模糊查询时,输入下划线,无法精确查到数据,而是返回所有的数据. 这让我很好奇,百度之后才发现,原来是因为有些特殊字符需要进行转义才可以进行查询 ...
- “System.Transactions.Diagnostics.DiagnosticTrace”的类型初始值设定项引发异常。
今天在项目中用log4net,App.config文件中增加了configSections节点,程序运行报错“System.Transactions.Diagnostics.DiagnosticTra ...

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