Android2.2 API 中文文档系列(6) —— ImageView
2015-10-23 15:19
791 查看
注意
原链接
http://www.cnblogs.com/over140/archive/2010/09/19/1830703.html
请查看本文后期更新完整版:
http://www.cnblogs.com/over140/archive/2011/06/08/2075054.html
正文
一、结构
java.lang.Object
android.view.View
android.widget.ImageView
已知直接子类:
ImageButton, QuickContactBadge
已知间接子类:
ZoomButton
二、类概述
显示任意图像,例如图标。ImageView类可以加载各种来源的图片(如资源或图片库),需要计算图像的尺寸,比便它可以在其他布局中使用,并提供例如缩放和着色(渲染)各种显示选项。
三、XML属性(原链接表中有效果图)
四、代码
4.1 android:tint
4.2 android:cropToPadding
五、 系列
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是难点,都花了超过一个小时才试出效果。
原链接
http://www.cnblogs.com/over140/archive/2010/09/19/1830703.html
请查看本文后期更新完整版:
http://www.cnblogs.com/over140/archive/2011/06/08/2075054.html
正文
一、结构
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 | 设置图片的填充方式。
| |||||||||||||||||||||||||||
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是难点,都花了超过一个小时才试出效果。
相关文章推荐
- Add platform android error
- Android灵动分析入门指南
- Android Design 安卓官方设计文档中文翻译——第一部分:引导
- android:minSdkVersion 之我见
- Android EditText 千分位格式化 删除也要自动格式化 监听小数点让用户只能输入小数点后几位
- Android编程ProgressBar自定义样式之动画模式实现方法
- Android自定义进度条
- Android学习笔记-自定义仿支付宝ProgressBar动画
- 安卓ORM框架之activeandroid
- Android
- android windowsoftinputmode属性详解
- Android编程中TextView字体属性设置方法(大小、字体、下划线、背景色)
- android支付之支付宝支付
- Android 使用 ANT 打包 Android 应用 .
- android——Android Studio上传项目到SVN
- android屏幕自适应
- android:visible = "invisible"和android:visible = "gone"的区别
- Android之Notification的多种用法
- 推荐的Android学习资料
- Android编程实现获取标题栏、状态栏的高度、屏幕大小及模拟Home键的方法