首页 技术 正文
技术 2022年11月23日
0 收藏 769 点赞 2,295 浏览 1427 个字

使用ImageView时经常会用到scaleType属性,如:

123456789 <ImageView    android:layout_width="50dp"    android:layout_height="50dp"    android:scaleType="matrix"     android:src="@drawable/sample_small" />

  

scaleType属性的各个值总是记不住之间的区别。今天找点时间总结了一下:

scaleType的属性值有:matrix   fitXY  fitStart   fitCenter  fitEnd  center   centerCrop  centerInside

它们之间的区别如下:

matrix 用矩阵来绘制(从左上角起始的矩阵区域) fitXY  把图片不按比例扩大/缩小到View的大小显示(确保图片会完整显示,并充满View) fitStart  把图片按比例扩大/缩小到View的宽度,显示在View的上部分位置(图片会完整显示) fitCenter  把图片按比例扩大/缩小到View的宽度,居中显示(图片会完整显示) fitEnd   把图片按比例扩大/缩小到View的宽度,显示在View的下部分位置(图片会完整显示) center  按图片的原来size居中显示,当图片宽超过View的宽,则截取图片的居中部分显示,当图片宽小于View的宽,则图片居中显示 centerCrop  按比例扩大/缩小图片的size居中显示,使得图片的高等于View的高,使得图片宽等于或大于View的宽 centerInside  将图片的内容完整居中显示,使得图片按比例缩小或原来的大小(图片比View小时)使得图片宽等于或小于View的宽 (图片会完整显示) 附上两张实验的截图:android ImageView scaleType属性(转) 图1: 图片比ImageView大的截图 android ImageView scaleType属性(转)图2: 图比ImageView小 实验截图  MATRIX矩阵可以动态缩小放大图片来显示,只是贴出相关语句,缩小图片: android ImageView scaleType属性(转)

 1 //获得Bitmap的高和宽
2 int bmpWidth=bmp.getWidth();
3 int bmpHeight=bmp.getHeight();
4
5 //设置缩小比例
6 double scale=0.8;
7 //计算出这次要缩小的比例
8 scaleWidth=(float)(scaleWidth*scale);
9 scaleHeight=(float)(scaleHeight*scale);
10
11 //产生resize后的Bitmap对象
12 Matrix matrix=new Matrix();
13 matrix.postScale(scaleWidth, scaleHeight);
14 Bitmap resizeBmp=Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true);

android ImageView scaleType属性(转)android ImageView scaleType属性(转)

1 <ImageView
2 android:id="@+id/image"
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent"
5 android:scaleType="center"
6 android:src="@drawable/candle"
7 />

android ImageView scaleType属性(转)** 要注意一点,Drawable文件夹里面的图片命名是不能大写的  在独处的过程中激发思考的力量……

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,023
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,360
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,143
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,774
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,853