联网获取到商品图片,显示时发现大小不合理,查资料发现得设置ScaleType属性:

<ImageView            android:id="@+id/grid_item_mainpage_web_image"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:scaleType="fitXY"            android:src="@drawable/shop_img_default" />
关于这个属性,Android Developer 解释如下,顺便从别人博客里找了点通俗易懂的国语版:

public static finalImageView.ScaleTypeCENTER

Added in API level 1

Center the image in the view, but perform no scaling. From XML, use this syntax:android:scaleType="center".

按图片的本来的大小居中显示,如果图片宽(高)超过View的宽(高),则截取图片的居中部分显示

public static finalImageView.ScaleTypeCENTER_CROP

Added in API level 1

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). The image is then centered in the view. From XML, use this syntax:android:scaleType="centerCrop".

按比例扩大图片到宽(高)等于或大于View的宽(高),并截取图片的居中部分显示

public static finalImageView.ScaleTypeCENTER_INSIDE

Added in API level 1

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). The image is then centered in the view. From XML, use this syntax:android:scaleType="centerInside".

按比例缩小图片到(高)等于或小于View的宽(高),并居中显示

public static finalImageView.ScaleTypeFIT_CENTER

Added in API level 1

Scale the image usingCENTER. From XML, use this syntax:android:scaleType="fitCenter".

按比例缩放图片到宽度等于View的宽度,并居中显示

public static finalImageView.ScaleTypeFIT_END

Added in API level 1

Scale the image usingEND. From XML, use this syntax:android:scaleType="fitEnd".

按比例缩放图片到宽度等于View的宽度,并显示在View的底部

public static finalImageView.ScaleTypeFIT_START

Added in API level 1

Scale the image usingSTART. From XML, use this syntax:android:scaleType="fitStart".

按比例缩放图片到宽度等于View的宽度,并显示在View的顶部

public static finalImageView.ScaleTypeFIT_XY

Added in API level 1

Scale the image usingFILL. From XML, use this syntax:android:scaleType="fitXY".

不按比例缩放图片,使图片的宽高等于View的宽高,填满View

public static finalImageView.ScaleTypeMATRIX

Added in API level 1

Scale using the image matrix when drawing. The image matrix can be set usingsetImageMatrix(Matrix). From XML, use this syntax:android:scaleType="matrix".

用矩阵来绘制图片(从左上角起),动态缩小或放大图片



更多相关文章

  1. android中加载图片时出现oom
  2. android 常用Bitmap处理方法收集:普通裁剪,缩放,圆形裁剪
  3. TextView的使用
  4. Android(安卓)图片处理方法大全
  5. 记一次Android(安卓)OOM探险之旅
  6. Android中使用gridview如何让图片在上文字在下
  7. android 让ImageView的图片全屏填充
  8. Android(安卓)调用相册 拍照 实现系统控件缩放 切割图片
  9. Android(安卓)将View 转化为bitmap 图片

随机推荐

  1. Android(安卓)配置文件 AndroidManifest
  2. android多设备界面适配的利器:属性weight
  3. Android设置边框样式
  4. android使用单选并设置按钮提醒
  5. Android(安卓)Layout: TableLayout
  6. 阿萨asdasdasd
  7. android > EditText 控件操作
  8. android 水平 垂直 滚动
  9. Android(安卓)Wear - Design Principles
  10. RelativeLayout布局的空间平分屏幕问题