网络上下载下来的图片自适应: android:adjustViewBounds="true"(其详细解释在下面)
<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

是否保持宽高比。需要与maxWidthMaxHeight一起使用,否则单独使用没有效果。

android:cropToPadding

是否截取指定区域用空白代替。单独设置无效果,需要与scrollY一起使用,效果如下,实现代码见代码部分:

ImageView图片自适应" style="margin:0px; padding:0px; border:0px; list-style:none">

android:maxHeight

设置View的最大高度,单独使用无效,需要与setAdjustViewBounds一起使用。如果想设置图片固定大小,又想保持图片宽高比,需要如下设置:

1)设置setAdjustViewBoundstrue

2)设置maxWidthMaxHeight

3)设置设置layout_widthlayout_heightwrap_content

android:maxWidth

设置View的最大宽度。同上。

android:scaleType

设置图片的填充方式。

matrix

0

用矩阵来绘图

fitXY

1

拉伸图片(不按比例)以填充View的宽高

ImageView图片自适应" style="margin:0px; padding:0px; border:0px; list-style:none" width="1" height="1">

layout_

height

:30px


layout_

width

:120px

fitStart

2

按比例拉伸图片,拉伸后图片的高度为View的高度,且显示在View的左边

ImageView图片自适应" style="margin:0px; padding:0px; border:0px; list-style:none" width="1" height="1">

fitCenter

3

按比例拉伸图片,拉伸后图片的高度为View的高度,且显示在View的中间

ImageView图片自适应" style="margin:0px; padding:0px; border:0px; list-style:none" width="1" height="1">

fitEnd

4

按比例拉伸图片,拉伸后图片的高度为View的高度,且显示在View的右边

ImageView图片自适应" style="margin:0px; padding:0px; border:0px; list-style:none" width="1" height="1">

center

5

按原图大小显示图片,但图片宽高大于View的宽高时,截图图片中间部分显示ImageView图片自适应" style="margin:0px; padding:0px; border:0px; list-style:none" width="1" height="1">

layout_

height

:60px


layout_

width

:80px


padding

:10px

centerCrop

6

按比例放大原图直至等于某边View的宽高显示。ImageView图片自适应" style="margin:0px; padding:0px; border:0px; list-style:none" width="1" height="1">

centerInside

7

当原图宽高或等于View的宽高时,按原图大小居中显示;反之将原图缩放至View的宽高居中显示。ImageView图片自适应" style="margin:0px; padding:0px; border:0px; list-style:none" width="1" height="1">

android:src

设置Viewdrawable(如图片,也可以是颜色,但是需要指定View的大小)

android:tint

将图片渲染成指定的颜色。见下图:

ImageView图片自适应" style="margin:0px; padding:0px; border:0px; list-style:none" width="1" height="1">左边为原图,右边为设置后的效果,见后面代码。

更多相关文章

  1. Android(安卓)Studio 学习笔记
  2. android图片压缩质量参数Bitmap.Config RGB_565等的含义
  3. android 透明显示
  4. android背景选择器selector用法
  5. Android(安卓)常用对话框Dialog封装
  6. 【ImageView】图片自适应及android:scaleType属性
  7. Android手机开发 控件 TextView文字居中
  8. Android(安卓)关闭/打开多点触控 (Android中设置不能同时点击2个v
  9. Android(安卓)属性总结

随机推荐

  1. Android中gravity和weight參數的用法
  2. Android星星评分控件RatingBar的使用
  3. Linux Kernel and Android(安卓)休眠与唤
  4. Android深入浅出之Audio第三部分Audio Po
  5. android鍩轰簬tcpdump鐨勬暟鎹寘鎹曡幏
  6. Android(安卓)Application类的详细介绍
  7. android中的HandlerThread类的学习
  8. Android系统做了哪些优化?
  9. Android的Handler总结
  10. android、IOS 基于webview 与 HTML 的集