android imageView 自适应大小
转自:http://blog.sina.com.cn/s/blog_618199e60100y537.html
<ImageView android:id="@+id/dynamic_item_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top" android:layout_marginTop="5dip" android:adjustViewBounds="true" android:background="@drawable/imageview_background" />
另外,android:background="@drawable/imageview_background"是给图片加了一个边框,其中
imageview_background.xml:
<?xmlversion="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"><solid android:color="@color/white"/><stroke android:width="2.0dip"android:color="#99D9D9D9" /> <cornersandroid:radius="2.0dip" /> <paddingandroid:left="5.0dip" android:top="5.0dip" android:right="5.0dip"android:bottom="5.0dip" /></shape>
ImageView属性说明:
1、类概述
显示任意图像,例如图标。ImageView类可以加载各种来源的图片(如资源或图片库),需要计算图像的尺寸,比便它可以在其他布局中使用,并提供例如缩放和着色(渲染)各种显示选项。
2、XML属性
属性名称 | 描述 | |||||||||||||||||||||||||||
android:adjustViewBounds | 是否保持宽高比。需要与maxWidth、MaxHeight一起使用,否则单独使用没有效果。 | |||||||||||||||||||||||||||
android:cropToPadding | 是否截取指定区域用空白代替。单独设置无效果,需要与scrollY一起使用,效果如下,实现代码见代码部分: ImageView图片自适应" style="margin:0px; padding:0px; border:0px; list-style:none">
| |||||||||||||||||||||||||||
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 | 将图片渲染成指定的颜色。见下图: ImageView图片自适应" style="margin:0px; padding:0px; border:0px; list-style:none" width="81" height="69">左边为原图,右边为设置后的效果,见后面代码。 |
更多相关文章
- Android(安卓)Base64字符串转换成图片
- 有米平台 发布android软件教程
- android 录音
- android开发之res下的menu (xml+代码的形式)
- android个人中心页面的设计
- android折叠展开列表测试
- Android(安卓)下载图片的问题
- android eclipse 项目相互引用设置
- Android(安卓)View转换成图片保存