Android工作学习笔记之图片自适应imageview属性android:scaleType
2013-06-02 14:56
507 查看
安卓的适配一直是一件头疼的事情.
特别是图片.有的时候总是忽大忽小.
以前习惯于从服务器下载图片后,再写一个工具类来缩减成指定的大小,然后放进指定控件.
其实不用那么麻烦,ImageView控件中有一个android:scaleType属性。
即ImageView.setScaleType(ImageView.ScaleType)
Sdk中介绍作用为:Options for scaling the bounds of an image to the bounds of this view.
大体意思为:一些缩放边界来控制图片视图的界限范围的选项
说白了,就是控制ImageView的边界显示方式.
例如:
如果获取到的图片的长宽比例是固定的,假设1:1.
设计要去在480*800的分辨率上要显示大小为60*60
那对于的属性就设置为:
这样,只要你获取到的图片的比例是1:1,无论图片多大,他都会按照60*60的大小来显示。
(60px在480*800下为40dip,(60 -0.5) / 1.5=…)
这样就不需要单独写一个工具来缩放图片了,而且在多分辨率适配的时候,适应能力也大大加强了。
原文地址:/article/6600073.html
特别是图片.有的时候总是忽大忽小.
以前习惯于从服务器下载图片后,再写一个工具类来缩减成指定的大小,然后放进指定控件.
其实不用那么麻烦,ImageView控件中有一个android:scaleType属性。
即ImageView.setScaleType(ImageView.ScaleType)
Sdk中介绍作用为:Options for scaling the bounds of an image to the bounds of this view.
大体意思为:一些缩放边界来控制图片视图的界限范围的选项
说白了,就是控制ImageView的边界显示方式.
CENTER Center the image in the view, but perform no scaling. 按图片的原来size居中显示,当图片长/宽超过View的长/宽,则截取图片的居中部分显示. CENTER_CROP Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding). 按比例扩大图片的size居中显示,使得图片长(宽)等于或大于View的长(宽) CENTER_INSIDE Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding). 将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于View的长/宽 FIT_CENTER Scale the image using CENTER. 把图片按比例扩大/缩小到View的宽度,居中显示 FIT_END Scale the image using END. 把图片按比例扩大/缩小到View的宽度,显示在View的下部分位置 FIT_START Scale the image using START. 把图片按比例扩大/缩小到View的宽度,显示在View的上部分位置 FIT_XY Scale the image using FILL. 把图片不按比例 扩大/缩小到View的大小显示 MATRIX Scale using the image matrix when drawing. 用矩阵来绘制
例如:
如果获取到的图片的长宽比例是固定的,假设1:1.
设计要去在480*800的分辨率上要显示大小为60*60
那对于的属性就设置为:
android:layout_width="40dip" android:layout_height="40dip" android:scaleType="fitXY"
这样,只要你获取到的图片的比例是1:1,无论图片多大,他都会按照60*60的大小来显示。
(60px在480*800下为40dip,(60 -0.5) / 1.5=…)
这样就不需要单独写一个工具来缩放图片了,而且在多分辨率适配的时候,适应能力也大大加强了。
原文地址:/article/6600073.html
相关文章推荐
- ANDROID工作学习笔记之图片自适应IMAGEVIEW属性ANDROID:SCALETYPE
- Android工作学习笔记之图片自适应imageview属性android:scaleType
- ANDROID工作学习笔记之ANDROID:SCALETYPE的秘密
- ImageView的属性android:scaleType
- ImageView中android:scaleType属性失败
- android-topeka学习笔记(一)-----一些不知道的属性
- Qt学习笔记之图片显示(自动调整大小适应设计的范围)
- googlesamples/android-topeka学习笔记(一)-----一些不知道的属性
- Android开发学习笔记:EditText的属性介绍
- Android笔记系列--ImageView 的scaletype属性
- CSS3学习笔记 之 图片边框属性
- 图片基础知识梳理(1) - ImageView 的 ScaleType 属性解析
- android 学习笔记13-新特性Fragment 帧动画 补间动画 属性动画
- android 开发零起步学习笔记(十八):Android Layout 布局属性全解
- 工作学习笔记——Alljoyn技术、初试Android开发
- ImageView的属性android:scaleType作用
- Android网络图片加载缓存处理库的使用---第三方库学习笔记(五)
- ImageView的属性android:scaleType
- Android中实现图片的异步加载学习笔记
- Android开发学习笔记之通过API接口将LaTex数学函数表达式转化为图片形式