1、添加Fresco依赖
compile 'com.facebook.fresco:fresco:0.12.0'
compile 'com.facebook.fresco:animated-gif:0.12.0'
2、添加权限
<uses-permission android:name="android.permission.INTERNET"/>
3、Fresco图片缓存(MyApp)
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
Fresco.initialize(this);
}
}
4、在清单中添加MyApp
![这里写图片描述](https://img-blog.csdn.net/20171102194732334?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMzk0OTM3Nzc=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
android:name=".MyApp"
5、布局(activity_main)
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/main_sdv2"
android:layout_marginTop="20dp"
android:layout_width="200dp"
android:layout_height="200dp"
fresco:actualImageScaleType="focusCrop"
fresco:placeholderImage="@mipmap/placeholder_image"
fresco:placeholderImageScaleType="focusCrop"
fresco:progressBarImage="@mipmap/progress_image"
fresco:progressBarImageScaleType="focusCrop"
fresco:progressBarAutoRotateInterval="5000"
fresco:failureImage="@mipmap/error"
fresco:failureImageScaleType="focusCrop"
fresco:retryImage="@mipmap/retry"
fresco:retryImageScaleType="focusCrop"
fresco:fadeDuration="5000"
fresco:backgroundImage="@android:color/holo_orange_light"
fresco:roundAsCircle="true"
fresco:roundedCornerRadius="30dp"
fresco:roundTopLeft="true"
fresco:roundTopRight="true"
fresco:roundBottomLeft="true"
fresco:roundBottomRight="true"
fresco:roundingBorderWidth="10dp"
fresco:roundingBorderColor="#008dd7"
/>
6、主Activity(MainActivity)
//网络图片
Uri uri = Uri.parse("http://b370.photo.store.qq.com/psb?/V14YKAbO0HQVDi/lqU0YAlRybs1Qnq168OGhqg2XhAd*ggnfWk7Oay6ZCI!/b/dHIBAAAAAAAA&bo=WgBaAFoAWgACPBg!&rf=viewer_4")
SimpleDraweeView draweeView1 = (SimpleDraweeView) findViewById(R.id.main_sdv2)
draweeView1.setImageURI(uri)
//创建DraweeController
DraweeController controller = Fresco.newDraweeControllerBuilder()
//重试之后要加载的图片URI地址
.setUri(uri)
//设置点击重试是否开启
.setTapToRetryEnabled(true)
//动画播放
.setAutoPlayAnimations(true)
//设置旧的Controller
.setOldController(draweeView1.getController())
//构建
.build()
//设置DraweeController
draweeView1.setController(controller)