联网获取到商品图片,显示时发现大小不合理,查资料发现得设置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" />
public static final ImageView.ScaleType CENTER
Center the image in the view, but perform no scaling. From XML, use this syntax: android:scaleType="center"
.
按图片的本来的大小居中显示,如果图片宽(高)超过View的宽(高),则截取图片的居中部分显示
public static final ImageView.ScaleType 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). The image is then centered in the view. From XML, use this syntax: android:scaleType="centerCrop"
.
按比例扩大图片到宽(高)等于或大于View的宽(高),并截取图片的居中部分显示
public static final ImageView.ScaleType 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). The image is then centered in the view. From XML, use this syntax: android:scaleType="centerInside"
.
按比例缩小图片到宽(高)等于或小于View的宽(高),并居中显示
public static final ImageView.ScaleType FIT_CENTER
Scale the image using CENTER
. From XML, use this syntax: android:scaleType="fitCenter"
.
按比例缩放图片到宽度等于View的宽度,并居中显示
public static final ImageView.ScaleType FIT_END
Scale the image using END
. From XML, use this syntax: android:scaleType="fitEnd"
.
按比例缩放图片到宽度等于View的宽度,并显示在View的底部
public static final ImageView.ScaleType FIT_START
Scale the image using START
. From XML, use this syntax: android:scaleType="fitStart"
.
按比例缩放图片到宽度等于View的宽度,并显示在View的顶部
public static final ImageView.ScaleType FIT_XY
Scale the image using FILL
. From XML, use this syntax: android:scaleType="fitXY"
.
不按比例缩放图片,使图片的宽高等于View的宽高,填满View
public static final ImageView.ScaleType MATRIX
Scale using the image matrix when drawing. The image matrix can be set using setImageMatrix(Matrix)
. From XML, use this syntax: android:scaleType="matrix"
.
用矩阵来绘制图片(从左上角起),动态缩小或放大图片