一.介绍
ImageView用来显示任意图像图片,可以自己定义显示尺寸,显示颜色等等.
二.XML属性
android:adjustViewBounds 是否保持宽高比。需要与maxWidth、MaxHeight一起使用,单独使用没有效果。
android:cropToPadding 是否截取指定区域用空白代替。单独设置无效果,需要与scrollY一起使用
android:maxHeight 定义View的最大高度,需要与AdjustViewBounds一起使用,单独使用没有效果。如果想设置图片固定大小,又想保持图片宽高比,需要如下设置:
1) 设置AdjustViewBounds为true;
2) 设置maxWidth、MaxHeight;
3) 设置设置layout_width和layout_height为wrap_content。
android:maxWidth 设置View的最大宽度。
android:scaleType 设置图片的填充方式。
android:src 设置View的图片或颜色
android:tint 将图片渲染成指定的颜色。
---------------------------------------------------------------------------------------------
使用Martix(android.graphics.Matrix)类中的postScale()方法结合Bitmap来实现缩放图片的功能
Bitmap bmp = BitmapFactory.decodeResource(getResource(),R.drawalbe.icon1)
int bmpwidth = bmp.getWidth();
int bmpheight = bmp.getHeight();
Matrix matrix = new Matrix();
matrix.postScale(width,height);
Bitmap bm = Bitmap.createBitmap(bmp,0,0,bmpwidth,bmpheight ,matrix,true);
imageView.setImageBitmap(bm);
在Android中不允许ImageView在产生后,动态修改其长度和宽度,
所以要实现图片发大缩小的功能,必须将原来的ImageView移除,
重新产生一个新的ImageView,并且指定图片来源给它,再放入Layout中
--------------------------------------------------------------------------------------------------
1、public voidsetVisibility (int visibility)
visibility One of VISIBLE, INVISIBLE, or GONE
但是在调用此方法的时候
image.setVisibility(visibility)
其中visibility是int型的参数。对应上面:VISIBLE=0x00000000;INVISIBLE=0x00000004;GONE=0x00000008。
即:
image.setVisibility(0x00000000) / image.setVisibility(View.VISIBLE); 表示显示;
image.setVisibility(0x00000004) / image.setVisibility(View.INVISIBLE);表示隐藏;
image.setVisibility(0x00000008) / image.setVisibility(View.GONE);表示view不存在。
2、设置颜色的不同方法
color.rgb(255,255,255);
color.RED;
color.parseColor(colorString); 其中colorString可以是:#RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray' 等
3、设置图片指定大小
protected Bitmap scaleImg(Bitmap bm, int newWidth, int newHeight) {
// 图片源
// Bitmap bm = BitmapFactory.decodeStream(getResources()
// .openRawResource(id));
// 获得图片的宽高
int width = bm.getWidth();
int height = bm.getHeight();
// 设置想要的大小
int newWidth1 = newWidth;
int newHeight1 = newHeight;
// 计算缩放比例
float scaleWidth = ((float) newWidth1) / width;
float scaleHeight = ((float) newHeight1) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix,
true);
return newbm;
}
调用:
获得18×18的图片
Bitmap bm = BitmapFactory.decodeStream(getResources().openRawResource(R.drawable.icon));
Bitmap newBm = scaleImg(bmImg , 18, 18);
imageView.setImageBitmap(newBm);
android:scaleType:
android:scaleType是控制图片如何resized/moved来匹对ImageView的size。ImageView.ScaleType / android:scaleType值的意义区别:
CENTER /center 按图片的原来size居中显示,当图片长/宽超过View的长/宽,则截取图片的居中部分显示
CENTER_CROP / centerCrop 按比例扩大图片的size居中显示,使得图片长(宽)等于或大于View的长(宽)
CENTER_INSIDE / centerInside 将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于View的长/宽
FIT_CENTER / fitCenter 把图片按比例扩大/缩小到View的宽度,居中显示
FIT_END / fitEnd 把图片按比例扩大/缩小到View的宽度,显示在View的下部分位置
FIT_START / fitStart 把图片按比例扩大/缩小到View的宽度,显示在View的上部分位置
FIT_XY / fitXY 把图片 不按比例 扩大/缩小到View的大小显示
MATRIX / matrix 用矩阵来绘制,动态缩小放大图片来显示。
ImageView用来显示任意图像图片,可以自己定义显示尺寸,显示颜色等等.
二.XML属性
android:adjustViewBounds 是否保持宽高比。需要与maxWidth、MaxHeight一起使用,单独使用没有效果。
android:cropToPadding 是否截取指定区域用空白代替。单独设置无效果,需要与scrollY一起使用
android:maxHeight 定义View的最大高度,需要与AdjustViewBounds一起使用,单独使用没有效果。如果想设置图片固定大小,又想保持图片宽高比,需要如下设置:
1) 设置AdjustViewBounds为true;
2) 设置maxWidth、MaxHeight;
3) 设置设置layout_width和layout_height为wrap_content。
android:maxWidth 设置View的最大宽度。
android:scaleType 设置图片的填充方式。
android:src 设置View的图片或颜色
android:tint 将图片渲染成指定的颜色。
---------------------------------------------------------------------------------------------
使用Martix(android.graphics.Matrix)类中的postScale()方法结合Bitmap来实现缩放图片的功能
Bitmap bmp = BitmapFactory.decodeResource(getResource(),R.drawalbe.icon1)
int bmpwidth = bmp.getWidth();
int bmpheight = bmp.getHeight();
Matrix matrix = new Matrix();
matrix.postScale(width,height);
Bitmap bm = Bitmap.createBitmap(bmp,0,0,bmpwidth,bmpheight ,matrix,true);
imageView.setImageBitmap(bm);
在Android中不允许ImageView在产生后,动态修改其长度和宽度,
所以要实现图片发大缩小的功能,必须将原来的ImageView移除,
重新产生一个新的ImageView,并且指定图片来源给它,再放入Layout中
--------------------------------------------------------------------------------------------------
1、public voidsetVisibility (int visibility)
visibility One of VISIBLE, INVISIBLE, or GONE
但是在调用此方法的时候
image.setVisibility(visibility)
其中visibility是int型的参数。对应上面:VISIBLE=0x00000000;INVISIBLE=0x00000004;GONE=0x00000008。
即:
image.setVisibility(0x00000000) / image.setVisibility(View.VISIBLE); 表示显示;
image.setVisibility(0x00000004) / image.setVisibility(View.INVISIBLE);表示隐藏;
image.setVisibility(0x00000008) / image.setVisibility(View.GONE);表示view不存在。
2、设置颜色的不同方法
color.rgb(255,255,255);
color.RED;
color.parseColor(colorString); 其中colorString可以是:#RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray' 等
3、设置图片指定大小
protected Bitmap scaleImg(Bitmap bm, int newWidth, int newHeight) {
// 图片源
// Bitmap bm = BitmapFactory.decodeStream(getResources()
// .openRawResource(id));
// 获得图片的宽高
int width = bm.getWidth();
int height = bm.getHeight();
// 设置想要的大小
int newWidth1 = newWidth;
int newHeight1 = newHeight;
// 计算缩放比例
float scaleWidth = ((float) newWidth1) / width;
float scaleHeight = ((float) newHeight1) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix,
true);
return newbm;
}
调用:
获得18×18的图片
Bitmap bm = BitmapFactory.decodeStream(getResources().openRawResource(R.drawable.icon));
Bitmap newBm = scaleImg(bmImg , 18, 18);
imageView.setImageBitmap(newBm);
android:scaleType:
android:scaleType是控制图片如何resized/moved来匹对ImageView的size。ImageView.ScaleType / android:scaleType值的意义区别:
CENTER /center 按图片的原来size居中显示,当图片长/宽超过View的长/宽,则截取图片的居中部分显示
CENTER_CROP / centerCrop 按比例扩大图片的size居中显示,使得图片长(宽)等于或大于View的长(宽)
CENTER_INSIDE / centerInside 将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于View的长/宽
FIT_CENTER / fitCenter 把图片按比例扩大/缩小到View的宽度,居中显示
FIT_END / fitEnd 把图片按比例扩大/缩小到View的宽度,显示在View的下部分位置
FIT_START / fitStart 把图片按比例扩大/缩小到View的宽度,显示在View的上部分位置
FIT_XY / fitXY 把图片 不按比例 扩大/缩小到View的大小显示
MATRIX / matrix 用矩阵来绘制,动态缩小放大图片来显示。
发表评论
-
android:gravity / android:layout_Gravity,android:padding / android:layout_margin
2012-04-07 15:21 1068android:gravity / android:layou ... -
Android触控屏幕Gesture(GestureDetector和SimpleOnGestureListener的使用教程)
2011-11-18 16:51 8181、当用户触摸屏幕的时候,会产生许多手势,例如down,up, ... -
简述Android触摸屏手势识别
2011-11-16 16:45 924很多时候,利用触摸屏的Fling、Scroll等Gesture ... -
简述Android触摸屏手势识别
2011-11-16 15:49 914在Android系统中,手势的识别是通过 GestureDet ... -
Android TextView属性详解
2011-11-10 17:12 753android:autoLink设置是否当 ... -
android监听返回按钮事件
2011-11-08 18:38 735用户在点击手机的返回按钮时,默认是推出当前的activty,但 ... -
android 完全退出程序
2011-11-08 18:37 728有几个activity,有一需 ... -
Android onTouchEvent, onClick及onLongClick的调用机制
2011-11-07 15:31 900针对屏幕上的一个View控 ... -
Android WebView放大缩小缩放
2011-11-02 10:27 2531一般情况下通过设置一下参数缩放 wv.getSettings ... -
Android控件之ZoomControls缩放控件
2011-11-01 17:14 1080一、简介 ZoomControls是一组可缩放的控件。它 ... -
Android通过手势实现的缩放处理
2011-11-01 17:12 1028主要原理是onTouchEvent事件中的参数MotionEv ... -
TextView 加下划线
2011-10-30 14:10 967如果是在资源文件里,可以这样写. Xml代码 ... -
Android TextView(EditView)文字底部或者中间加横线
2011-10-30 14:08 1634promotionLinkText = (TextView) ... -
TextView中显示HTML和图片
2011-10-30 13:55 1064在TextView中显示<img src="& ... -
Android 背景图片重复 Background repeat
2011-10-29 00:45 3192以LinearLayout为例,它提供的background属 ... -
android 3d 旋转
2011-10-27 16:23 1145在javaeye里看到了关于3d旋转的文章 效果图: 这 ... -
android 之 GridView
2011-10-27 14:14 761GridView 的用法基本与ListView类似。 ... -
android GridView的使用
2011-10-27 14:12 1401GridView跟ListView都是比较常用的多控件布局,而 ... -
android之ImageView
2011-10-26 22:17 963ImageView 首先确定下ImageView的全路径: ... -
布局学习—活用RelativeLayout
2011-10-26 00:40 653前言 Android布局中RelativeLayout非 ...
相关推荐
(android控件) ImageView 控件开发效果总结 (多组滤镜效果)源码下载
本篇文章是对android中ImageView的使用技巧进行了几点经验总结,需要的朋友参考下
android Bitmap用法总结 Bitmap用法总结 1、Drawable → Bitmap public static Bitmap drawableToBitmap(Drawable drawable) { Bitmap bitmap = Bitmap .createBitmap( drawable.getIntrinsicWidth(), drawable....
本文实例讲述了Android编程实现自定义ImageView圆图功能的方法。分享给大家供大家参考,具体如下: 首先很感谢开源项目Universal Image Loader图片加载框架。之前也看过一段时间框架源码,但是却没有时间进行知识点...
代码中的例子如下: 代码如下:<ImageView android:id=”@+id/iv_bit_1″ android:layout_width=”@dimen/passcode_width” android:layout_height=”@dimen/passcode_height” android:scaleType=”fitXY”> <...
android横竖屏总结.doc Android 的手势拖动切换ViewViewFlipper.doc Eclipse内存不足的解决办法.doc EditView 阻止软键盘自动弹出.doc HttpClient的一个应用的例子(图片下载).txt RatingBar 更换图片.doc ...
里面是我对DataBinding的总结,有相应的注释适合学习,希望多提建议,互相学习互相进步。文章:http://blog.csdn.net/weiwozhiyi/article/details/52181532
android横竖屏总结.doc Android 的手势拖动切换ViewViewFlipper.doc Eclipse内存不足的解决办法.doc EditView 阻止软键盘自动弹出.doc HttpClient的一个应用的例子(图片下载).txt RatingBar 更换图片.doc TextView...
android:layout_margin="10dp" tools:layout_editor_absoluteX="10dp"> <ImageView android:id="@+id/icol" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParent...
采用案例驱动模式展开讲解知识点,即介绍案例->案例涉及技术->展开知识点->总结的方式 本书作者从事多年一线开发和培训,讲解知识点力求细致,深入浅出 目 录 前言 第1章 Android操作系统概述 1 1.1 Android...
这几天一直在研究github上的PhotoView跟GestureImageView,发现写的都很牛,看了很久的代码,于是打算把自己所看的一些东西总结一下,内容还是很多的,但是很有含金量哈~~ 先附上两个开源项目的链接: ...
最无私的Android资料(书籍+代码)分享[总结] Android中文帮助教程(非常合适新手入门) android程序编写及调试新手入门 大家一起学Android(Windows篇) android入门与提高必看指南 Android入门逆引手册 Android...
接下来总结下目前能够实现pdf阅读的方案,开发当中需要根据实际需求去选择相应的方案。 1.使用Google doc支持来展示word,excel,pdf,txt(WebView方式在线预览): <span xss=removed>WebView urlWebView = (WebView)...
总结与体会 通过学习开发扑克牌计算24点app,了解了android studio开发的基本原理。学习了android程序的运行过程。一个进程创建时系统会为它创建一个Activity(活动),紧接着调用onCreate(),onCreate()中主要是...
这里总结了网上的最优方法:将图像处理成圆角,然后在加载给ImageView显示,代码如下: public Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth...
本文实例讲述了Android编程实现画板功能的...第二种方式的思路是,先用Canvas绘制一张空的Bitmap,通过ImageView的setImageBitmap()方法加载这个Bitmap,然后该ImageView实现onTouch()监听事件,跟踪用户手指的移动调
归纳总结: 1. 从缓存中读取图片:先从内存缓存中读取。 若是从内存中读取到的Bitmap为空,则在磁盘缓存中读取。 若是从磁盘中读取到的Bitmap为空,则从起始资源中读取 2.开启工作线程,执行从起始资源中读取...