一、对比显示ScaleType的不同效果
二、使用嵌套LinearLayout为每一张ImageView添加文字说明
三、ScaleType的8个属性简要说明:
1.scaleType=“matrix”
是保持原图大小、从左上角的点开始,以矩阵形式绘图。
2.scaleType=“fitXY”
不按比例缩放图片,目标是把图片塞满整个View。
3.scaleType=“fitStart”
是将原图沿左上角的点(即matrix方式绘图开始的点),按比例缩放原图绘制而成的。
4.scaleType=“fitCenter”
是将原图沿上方居中的点(即matrix方式绘图第一行的居中的点),按比例缩放原图绘制而成的。
5.scaleType=“fitEnd”
是将原图沿下方居中的点(即matrix方式绘图最后一行的居中的点),按比例缩放原图绘制而成的。
6.scaleType=“Center”
是保持原图大小,以原图的几何中心点和ImagView的几何中心点为基准,只绘制ImagView大小的图像。
7.scaleType=“centerCrop”
不保持原图大小,以原图的几何中心点和ImagView的几何中心点为基准,只绘制ImagView大小的图像(以填满ImagView为目标,对原图进行裁剪)。
3.scaleType=“centerInside”
不保持原图大小,以原图的几何中心点和ImagView的几何中心点为基准,只绘制ImagView大小的图像(以显示完整图片为目标,对原图进行缩放)。
四、设置方法
java:
使用setImageResource()设置使用的图片
使用setScaleType()设置图片拉伸属性
xml:
使用android:src="" 设置使用的图片
使用android:scaleType=""设置图片拉伸属性
先看原始图片:
效果图:
xml代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/field"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="matrix"
android:textColor="#ff00ff" />
<ImageView
android:id="@+id/imageViewId"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#f0f0f0"
android:scaleType="matrix"
android:src="@drawable/zhl" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fitXY"
android:textColor="#ff00ff" />
<ImageView
android:id="@+id/imageViewId"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#f0f0f0"
android:scaleType="fitXY"
android:src="@drawable/zhl" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fitStart"
android:textColor="#ff00ff" />
<ImageView
android:id="@+id/imageViewId"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#f0f0f0"
android:scaleType="fitStart"
android:src="@drawable/zhl" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fitCenter"
android:textColor="#ff00ff" />
<ImageView
android:id="@+id/imageViewId"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#f0f0f0"
android:scaleType="fitCenter"
android:src="@drawable/zhl" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fitEnd"
android:textColor="#ff00ff" />
<ImageView
android:id="@+id/imageViewId"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#f0f0f0"
android:scaleType="fitEnd"
android:src="@drawable/zhl" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="center"
android:textColor="#ff00ff" />
<ImageView
android:id="@+id/imageViewId"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#f0f0f0"
android:scaleType="center"
android:src="@drawable/zhl" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="centerCrop"
android:textColor="#ff00ff" />
<ImageView
android:id="@+id/imageViewId"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#f0f0f0"
android:scaleType="centerCrop"
android:src="@drawable/zhl" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginRight="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="centerInside"
android:textColor="#ff00ff" />
<ImageView
android:id="@+id/imageViewId"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#f0f0f0"
android:scaleType="centerInside"
android:src="@drawable/zhl" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
参考:点击打开链接
分享到:
相关推荐
参考资料-001-A04______报验申请表.zip
OpenGL三维摄像漫游源码,用VC++6.0和OpenGL编写的有关摄像漫游的源代码
通过本章节的学习,你将获得:(1) 初步了解龙芯体系结构教学实验箱(Artix-7)龙芯体系结构结构教学实验箱的核心是一块基于 FPGA 芯片的嵌入式系统开发板
Proteus8.9 VSM Studio WINAVR编译器仿真ATMega16系列a04_INT0及INT1中断编程代码和仿真操作实验
按图索骥学-机器学习 有关机器学习的一组教程,深入浅出 用一副思维导图串联所有学习资源和知识点,每个同学都可以根据自己的情况,按图索骥,设计自己的学习路径,学习需要的课程 有关此课程详细信息,请访问...
详细描述了vivado的使用全流程,从综合,布局布线,生成比特流到约束的编写
SAS-RAID_Driver_CP0KR_WN64_6.603.07.00_A04
A04_摄像漫游 第4 章源程序 A05_开天辟地 第5 章源程序 A06_OpenGL中显示文字 第6 章源程序 A07_特殊的平面_树 第7 章源程序 A08_显示3D模型 第8 章源程序 A09_3D动画 第9 章源程序 A10_射击、爆炸 第10章源程序 A11...
<br/> 目录: A01_OpenGL的程序框架 A02_OpenGL的基本图形 A03_OpenGL的组合图形 A04_摄像漫游 A05_开天辟地 A06_OpenGL中显示文字 A07_特殊的平面_树 A08_显示3D模型 A09_MD2动画模型...
5.STM8S-A04_UART基本收发数据 6.STM8S-A05_ADC单次软件触发 7.STM8S-A05_ADC连续转换 8.STM8S-A06_AWU自动唤醒(未校正LSI时钟) 9.STM8S-A06_AWU自动唤醒(已校正LSI时钟) 10.STM8S-A07_内部EEPROM编程 11.STM8S-...
A04_摄像漫游 第4 章源程序 A05_开天辟地 第5 章源程序 A06_OpenGL中显示文字 第6 章源程序 A07_特殊的平面_树 第7 章源程序 A08_显示3D模型 第8 章源程序 A09_3D动画 第9 章源程序 A10_射击、爆炸 第10章源...
几个3d游戏的源码包括:A01_OpenGL的程序框架,A04_摄像漫游,A05_开天辟地,A07_特殊的平面_树,A09_MD2动画模型,A12_碰撞检测,对3d游戏编程初学者有很大作用。
A01_Android的软硬整合潮流 A02_Android四大组件 A03_Android的进程和IPC...A04_Android的线程模式 A05_Android的软硬整合流程 A06_认识Android的UI架构 A07_SurfaceView与UI多线程与2D特效 A08_DB与ContentProvider
BC6145 A04 UFE Setup BC6145 A04 UFE 安装工具;装好后可调试下载程序到芯片里;
数学建模-07cumcm_a04.zip
a04e的工作原理,搞传感器的朋友都知道!
1、错误1(1)错误现象第35个测试点开始报错(2)分析定位过程有Z调Z,HI和LO的连接在更改过程中出了问题(3)错误原因删除注释冗余内容时不注意删掉了之前代
ADS131A04的数据手册,含中文翻译版本
松下FP0-A04V技术资料pdf,松下FP0-A04V技术资料