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 不 ...
随机推荐
- Eclipse用法和技巧十二:快速复制一行
写代码的总有那么个时候需要Ctrl+c,Ctrl+v,在eclipse中如果遇到需要快速在一行代码的上下复制一行的话,有很方便的快捷键可以使用.将光标放到某一行,按住Ctrl+Alt+Down,即可以 ...
- Clojure学习资料
以下大部分收藏自博客:http://blog.csdn.net/ithomer/article/details/17225813 官方文档: http://clojure.org/documentat ...
- 5种Web常见编码、变换算法的自动识别
#coding=utf-8 #识别字符序列变换算法,当前支持标准的MD5.SHA-1.Base64,及主流的URL编码.HTML编码 import re import sys #MD5判断函数 def ...
- linux杂谈(十九):DNSserver的配置(二)
1.本机和外网的解析 之前讨论了DNS的正向解析和反向解析,但有的时候我们想让DNSserver对于server本机的解析和对于外网的解析是不同的.那就须要在主配置文件里对本机和外网进行不同的配 ...
- 在LAMP环境下搭建JSP动态网页
开发环境Linux的版本号Linux localhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x ...
- struts2之入门login
1.struts 最小开发需要的jar有: struts2-core-2.2.3.jar :Struts 2框架的核心类库 xwork-core-2.2.3.jar :XWork类库,Struts 2 ...
- Linux文件查找命令find用法整理(locate/find)
Linux文件查找查找主要包括:locate和find 1.locate 用法简单,根据数据库查找,非实时,用法: locate FILENAME 手动更新数据库(时间可能较长) updatedb 2 ...
- python 面向对象简单理解
面向对象: 是一种程序设计范型 作用: 提高软件的重用性和灵活性,扩展性 世界万物一切皆为对象,对象即是指由特定状态,特征,行为的实体 知识点一: 代码的重用 举个栗子 比如小月月有了一个女朋友1 ...
- Fragment的生命周期和Activity之间的通信以及使用
Fragment通俗来讲就是碎片,不能单独存在,意思就是说必须依附于Activity,一般来说有两种方式把Fragment加到Activity,分为静态,动态. 静态即为右键单击,建立一个Fragme ...
- 枚举N行N列的自然数列
数据库环境:SQL SERVER 2005 现有一个需求,要枚举1-50个自然数,分10行5列展示.如图,

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