转自http://407827531.iteye.com/blog/1117199
正文
一、结构
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: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>
- <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>
相关推荐
介绍Android中gridview和imageview的部分属性
NULL 博文链接:https://sunzone.iteye.com/blog/1869915
ImageView的scaleType属性练习,具体请查看我的博客http://blog.csdn.net/u012702547/article/details/50586946
代码中的例子如下: 代码如下:<ImageView android:id=”@+id/iv_bit_1″ android:layout_width=”@dimen/passcode_width” android:layout_height=”@dimen/passcode_height” android:scaleType=”fitXY”> <...
android 自定义属性实现 ImageView 透明度渐变效果
ImageView 图片显示样式的几种类型。android:scaleType是控制图片如何resized/moved来匹对ImageView的size。
图片说明Andorid中ImageView的不同属性ScaleType的区别
图解说明android中ImageView的scaletype属性.rar
图解说明android 中ImageView的scaletype属性.pdf
图解说明android中ImageView的scaletype属性.pdf
ImageView基础属性详解 详见博文http://blog.csdn.net/a87b01c14/article/details/49615689
使用ImageView显示图片很简单,下面的教程在布局文件中直接通过布局属性将图片布局了,so easy的~~教程见:http://www.ourunix.org/android/post/125.html
自定义图像视图, 在 ImageView 的属性中设置悬停效果。 第 1 步:声明样式(my_styles.xml) < /declare-styleable > 第 2 步:自定义 ImageView(MyImageView.java) public class MyImageView extends ...
android自定义控件 imageview带有check和uncheck两种状态 目前check和uncheck的资源图片是写死的 没有做到xml可配置
这篇随笔将会简单的记录下ImageView这个控件的一些使用方法,以及其最重要的一个属性: scaleType ImageView这个控件是用来显示图片用的,例如我们可以通过下面这段xml配置来声明显示一张图片: <ImageView n...
自定义的Imageview,通过修改xml的属性就可实现图片的圆角,圆形,加边框等
图文相配很清晰的看出每个属性的效果, 感觉 CENTER_CROP 比较有用,长宽自动适应 ImageView ,整个图片自动缩略填充整个区域且居中显示(高宽不一定是view的尺寸),以前用JS在网页上实现的,在 android上一开始还...
本文实例讲述了Android开发中ImageView的scaletype属性用法。分享给大家供大家参考,具体如下: ImageView的属性android:scaleType,即 ImageView.setScaleType(ImageView.ScaleType)。android:scaleType是控制图片...
项目地址:https://github.com/zhaozhentao/MaterialImageView 效果图:如何使用:由于MaterialImageView是扩展了ImageView,支持ImageView的所有特性。 android:src="@drawable/pic1" android:layout_width=...