**1.引入fresco **
compile 'com.facebook.fresco:fresco:0.12.0'
如果有其他需要也可以引入其他的相關
// 在 API < 14 上的機器支持 WebP 時,需要添加
compile 'com.facebook.fresco:animated-base-support:0.12.0'
// 支持 GIF 動圖,需要添加
compile 'com.facebook.fresco:animated-gif:0.12.0'
// 支持 WebP (靜態圖+動圖),需要添加
compile 'com.facebook.fresco:animated-webp:0.12.0'
compile 'com.facebook.fresco:webpsupport:0.12.0'
// 僅支持 WebP 靜態圖,需要添加
compile 'com.facebook.fresco:webpsupport:0.12.0'
** 2.初始化 **
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Fresco.initialize(this);
}
}
** 3.使用 **
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
Uri uri = Uri.parse("http://img.hb.aicdn.com/a429c34f8d22216ee177c9bd4849b0980d18bfec6c7c6-VMOev7_fw658");
SimpleDraweeView imageView = (SimpleDraweeView) findViewById(R.id.image_view);
imageView.setImageURI(uri);
}
}
Paste_Image.png
**執行的任務: **
- 顯示占位圖直到加載完成;
- 下載圖片;
- 緩存圖片;
- 圖片不再顯示時,從內存中移除;