Frsco是facebook推出的android 图片框架,相对于glide,imageLoader而言具有更加完备的生态,但是介于其较其他图片框架中,在非以图片展示为主的application,这里并不建议用;但是不得不说Fresco是一个优秀的图片框架;
Fresco官网地址:https://github.com/facebook/fresco
1. 代码依赖
dependencies {
......
implementation 'com.facebook.fresco:fresco:1.9.0'
}
下面就开始进行使用了!
Fresco支持xml中自定义属性配置和代码设置;
2.Frsco初始化
在用Frsco加载图片之前进行Frsco的初始化:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fresco.initialize(this);
setContentView(R.layout.activity_main);
......
2.xml配置
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/img_fresco"
android:layout_width="300dp"
android:layout_height="wrap_content"
fresco:failureImage="@color/failure"
fresco:placeholderImage="@mipmap/ic_place"
fresco:placeholderImageScaleType="fitXY"
fresco:actualImageScaleType="centerCrop"
fresco:roundAsCircle="false"
fresco:roundedCornerRadius="100dp"
fresco:roundTopLeft="false"
fresco:roundTopRight="true"
fresco:roundBottomLeft="true"
fresco:roundBottomRight="false"
fresco:fadeDuration="10000"
fresco:progressBarImage="@mipmap/ic_loading"
fresco:progressBarAutoRotateInterval="2000"
fresco:progressBarImageScaleType="fitCenter"
fresco:overlayImage="@null"
fresco:pressedStateOverlayImage="@mipmap/ic_launcher_round"
fresco:retryImage="@mipmap/ic_place"
fresco:retryImageScaleType="fitCenter"
fresco:roundingBorderWidth="5dp"
fresco:roundingBorderColor="@color/failure"
fresco:viewAspectRatio="1"
/>
Frsco属性介绍:
类型 | 描述 |
---|---|
center | 居中,无缩放 |
centerCrop | 保持宽高比缩小或放大,使得两边都大于或等于显示边界。居中显示。 |
focusCrop | 同centerCrop, 但居中点不是中点,而是指定的某个点 |
centerInside | 使两边都在显示边界内,居中显示。如果图尺寸大于显示边界,则保持长宽比缩小图片。 |
fitCenter | 保持宽高比,缩小或者放大,使得图片完全显示在显示边界内。居中显示 |
fitStart | 同上。但不居中,和显示边界左上对齐 |
fitEnd | 同fitCenter, 但不居中,和显示边界右下对齐 |
fitXY | 不保存宽高比,填充满显示边界 |
none | 如要使用tile mode显示, 需要设置为none |
XML属性 | 意义 |
---|---|
fadeDuration | 淡入淡出动画持续时间(单位:毫秒ms) |
actualImageScaleType | 实际图像的缩放类型 |
placeholderImage | 占位图 |
placeholderImageScaleType | 占位图的缩放类型 |
progressBarImage | 进度图 |
progressBarImageScaleType | 进度图的缩放类型 |
progressBarAutoRotateInterval | 进度图自动旋转间隔时间(单位:毫秒ms) |
failureImage | 失败图 |
failureImageScaleType | 失败图的缩放类型 |
retryImage | 重试图 |
retryImageScaleType | 重试图的缩放类型 |
backgroundImage | 背景图 |
overlayImage | 叠加图 |
pressedStateOverlayImage | 按压状态下所显示的叠加图 |
roundAsCircle | 设置为圆形图 |
roundedCornerRadius | 圆角半径 |
roundTopLeft | 左上角是否为圆角 |
roundTopRight | 右上角是否为圆角 |
roundBottomLeft | 左下角是否为圆角 |
roundBottomRight | 右下角是否为圆角 |
roundingBorderWidth | 圆形或者圆角图边框的宽度 |
roundingBorderColor | 圆形或者圆角图边框的颜色 |
roundWithOverlayColor | 圆形或者圆角图底下的叠加颜色(只能设置颜色) |
viewAspectRatio | 控件纵横比 |
3.加载图片:
SimpleDraweeView img_fresco = findViewById(R.id.img_fresco);
String url = "http://ww1.sinaimg.cn/large/0065oQSqly1fs1vq7vlsoj30k80q2ae5.jpg";
loadImage(img_fresco,Uri.parse(url));
当然不仅仅是网络图片!!!