一、已经很久没有写博客了,有一些基本的常识没有搞清楚,这次使用代码亲自测试一把,首先来两张图片,一张小图分辨率为494x212;一张大图,分辨率为3840x2400。
二、再贴一下基本的xml代码:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/iv" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:scaleType="fitXY" android:src="@drawable/hhhhh" /> </RelativeLayout>
三、测试
1、android:scaleType="center"
说明:当图片长/宽小于View的长/宽,按图片的原来size居中显示;当图片长/宽超过View的长/宽,则截取图片的居中部分显示。
测试图片:
2、android:scaleType="centerCrop"按比例扩大图片的size居中显示,使得图片长(宽)等于或大于View的长(宽)
3、android:scaleType="centerInside"将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于View的长/宽。
4、
android:scaleType="fitCenter"把图片按比例扩大/缩小到View的宽度,居中显示,一般手机相册使用这种方式。
5、android:scaleType="fitStart"
6、
android:scaleType="fitEnd"
7、
android:scaleType="fitXY"不按比例缩放图片,目标是把图片塞满整个View。