A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© 不二晨 金牌黑马   /  2019-1-4 09:26  /  1059 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

第一步: 导依赖

//fresco基础
implementation 'com.facebook.fresco:fresco:1.11.0'

//下面的依赖根据需求,用到哪个模块,就导入对应的依赖即可.

// 仅支持 WebP 静态图,需要添加

  compile 'com.facebook.fresco:webpsupport:0.14.1'

// 支持 GIF 动图,需要添加

  compile 'com.facebook.fresco:animated-gif:0.14.1'

  // 支持 WebP 静态图及 WebP 动图,需要添加

compile 'com.facebook.fresco:animated-webp:0.14.1'

  compile 'com.facebook.fresco:webpsupport:0.14.1'
// 在 API < 14 上的机器支持 WebP 时,需要添加
  compile 'com.facebook.fresco:animated-base-support:0.14.1'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
第二步:布局

XML:  xmlns:fresco="http://schemas.android.com/apk/res-auto"
<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/SDV"
    android:layout_width="254dp"
    android:layout_height="254dp"
    fresco:placeholderImage="@mipmap/ic_launcher"
    />
1
2
3
4
5
6
7
第三步:全局设置

//设置磁盘缓存(可以不要)
    DiskCacheConfig diskCacheConfig = DiskCacheConfig.newBuilder(this)
            //设置缓存的目录名字
            .setBaseDirectoryName("images")
            //设置缓存的路径
            .setBaseDirectoryPath(Environment.getExternalStorageDirectory())
            .build();
    //设置磁盘缓存的配置,生成配置未见
    ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this)
            .setMainDiskCacheConfig(diskCacheConfig)
            .build();

//必须!!!!
    Fresco.initialize(this,config);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
第四步:代码中添加图片网址

//加载网络图片的网址
Uri uri = Uri.parse("图片网址");
//初始化控件
SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);
//加载图片
draweeView.setImageURI(uri);
1
2
3
4
5
6
第五步:如果需要联网,添加网络权限
---------------------
转载,仅作分享,侵删
作者:RQHN
原文:https://blog.csdn.net/weixin_43258668/article/details/85555991


1 个回复

倒序浏览
奈斯,加油
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马