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 不 ...
随机推荐
- jQuery 的属性操作方法
jQuery 属性操作方法 下面列出的这些方法获得或设置元素的 DOM 属性. 这些方法对于 XML 文档和 HTML 文档均是适用的,除了:html(). 方法 描述 addClass() 向匹配的 ...
- Android开发之50个常见实用技巧——活用布局
第一章.活用布局 Hack1. 使用weight属性实现视图的居中显示 ①合用weightSum属性和layout-weight属性 解决问题,如:居中显示按钮,并占据父视图的50%: 代码如: & ...
- jetty-如何配置虚拟主机【转】
jetty-如何配置虚拟主机[转]http://weifly.iteye.com/blog/1152688 官方配置:http://wiki.eclipse.org/Jetty/Howto/Confi ...
- Linux主机安全配置的几个脚本【转载】
标签:linux Linux主机安全配置的几个脚本 职场 休闲原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://hx100.blog ...
- ibatis 开发中的经验 (一)ibatis 和hibernate 在开发中的理解
这个项目的底层是用ibatis框架完毕,这几天也是都在用这个框架写代码,也有了一些简单的理解,把项目拿过来后基本的配置都已经配置好了,比方一些事务.日志控制等,在开发中主要用到的是写SQL语句以及熟悉 ...
- [rxjs] Async, handle data over time
If I have an array, and I want to apply filter, map, forEach to it. let Observable = Rx.Observable; ...
- 偷偷mark下一个
java书单 thinking in java java战 Effective Java 深入了解JVM虚拟机 java性能优化权威指南 JSR133 Google Guava官方教程 版权声明:本文 ...
- LRU算法&&LeetCode解题报告
题目 Design and implement a data structure for Least Recently Used (LRU) cache. It should support the ...
- Chapter 3 - How to Move a sprite
http://www.eoeandroid.com/forum.php?mod=viewthread&tid=250529 http://www.cocos2d-x.org/boards/6/ ...
- Apache Kafka: Next Generation Distributed Messaging System---reference
Introduction Apache Kafka is a distributed publish-subscribe messaging system. It was originally dev ...