android imageview 显示方式设置
来源:互联网 发布:尺八制作图数据 编辑:程序博客网 时间:2024/06/01 10:28
注意
请查看本文后期更新完整版:
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
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
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是难点,都花了超过一个小时才试出效果。
- android imageview 显示方式设置
- Android imageView设置 全屏显示
- android imageView 图片显示方式属性
- android imageView 图片显示方式属性
- android imageView 图片显示方式属性
- Android - 设置ImageView为全屏显示
- Android ImageView的显示方式 (scaleType属性与adjustViewBounds属性)
- ImageView的属性android:scaleType设置最佳比例图片显示
- ImageView的属性android:scaleType设置最佳比例图片显示
- ImageView的属性android:scaleType设置最佳比例图片显示
- Android开发教程--设置ImageView图片的显示比例
- Android笔记之ImageView设置图片以灰色显示
- Android imageView 全屏显示
- Android ImageView显示比例
- Android ImageView设置边框
- Android ImageView设置大小
- Android 设置ImageView全屏
- ImageView设置图片显示类型
- 两个升序表,打印L中那些由P所指定的位置上的元素 java实现
- LCS 解决最长子串(c++代码)
- Menu 实例
- 推荐一个免费的web打印插件
- 插入排序的优化,比较插入同步进行
- android imageview 显示方式设置
- 数据库存储过程
- 网站页面在浏览器中设置样式格式。
- Android实际开发中的bug总结与解决方法(一)
- ubuntu系统下usb转serial的使用
- 各种JS验证和操作
- ASP.NET Web API 简介
- CISCO和H3C交换机备份配置
- 百度地图sdk Android部署方法