导入依赖
//Fresco
implementation 'com.facebook.fresco:fresco:1.12.0'
在Application中初始化
//初始化
Fresco.initialize(this);
必须使用SimpleDraweeView控件才能实现 注意:宽或高必须的是固定值
<com.facebook.drawee.view.SimpleDraweeView
android:layout_width="400dp"
android:layout_height="300dp"
android:id="@+id/image"
fresco:placeholderImage="@drawable/holder"
fresco:failureImage="@drawable/err"
fresco:retryImage="@drawable/res"
fresco:roundAsCircle="true"
/>
//渐进式加载图片
//控件
SimpleDraweeView image=findViewById(R.id.img);
Uri uri = Uri.parse(bean.getMasterPic());//网络图片资源
ImageRequest build = ImageRequestBuilder.newBuilderWithSource(uri)
.setProgressiveRenderingEnabled(true).build();//设置渐进渲染已启用
AbstractDraweeController controller = Fresco.newDraweeControllerBuilder()
.setImageRequest(build)
.build();
//设置图片
image.setController(controller);
最后别忘了添加网络权限哦!
配置自定义外部缓存看这里//www.greatytc.com/p/c78819d29a3d