引入Fresco框架
来源:互联网 发布:windows直接进入桌面 编辑:程序博客网 时间:2024/06/03 06:05
Fresco 中设计有一个叫做 Image Pipeline 的模块。它负责从网络,从本地文件系统,本地资源加载图片。为了最大限度节省空间和CPU时间,它含有3级缓存设计(2级内存,1级磁盘)。
在这里简单的介绍一下使方法:更详细的使用方法以及API请参照https://www.fresco-cn.org/ 中午网站
1、添加相应的依赖
在app下的 bulid.gradle 下添加相应的依赖
// 其他依赖
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、从网络获取图片的同时不要忘记添加网络访问的权限
<uses-permission android:name="android.permission.INTERNET"/>
3、在APP 的入口处,对 fresco进行初始化
Fresco.initialize(this);
Fresco.initialize(this);要放在
setContentView(R.layout.activity_main);之前做初始化
4、有点需要特别的注意,使用Fresco的时候,必须使用它自带的 图片装载布局
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/my_image_view"
android:layout_height="300dp"
android:layout_width="300dp"
fresco:placeholderImage="@mipmap/ic_launcher"
/>
而非ImageView
5、加载一张普通的从网络获取的图片
SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);
draweeView.setImageURI(uri);
6、加载一张从网络获取的GIF图片
SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);
DraweeController mDraweeController = Fresco.newDraweeControllerBuilder()
.setAutoPlayAnimations(true)
//设置uri,加载本网络gif资源
.setUri(Uri.parse("http://img4.178.com/acg1/201506/227753817857/227754566617.gif"))//设置uri
.build();
//设置Controller
draweeView.setController(mDraweeController);
7、设置占位图
因为图片在加载出来之前,会有一段时间是空白的,为了看上去美观一些,我们需要加载一张过渡的图片
fresco:placeholderImage="@mipmap/ic_launcher"
但是这里有一点需要注意:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
红色部位代码必须加上
需要了解更多,请直接访问https://www.fresco-cn.org/
- 引入Fresco框架
- Fresco-引入篇
- Fresco框架的介绍
- Fresco图片加载框架
- 图片加载框架-Fresco
- Android Fresco框架入门
- Fresco图片加载框架
- 框架Fresco的使用
- Fresco图片加载框架
- 图片框架Fresco
- Fresco图片框架详解
- Fresco图片加载框架
- Androidstudio和Eclipse ADT引入Fresco
- 引入Fresco 网络加载图片的学习
- FRESCO:SDN安全控制器框架
- Fresco 图片加载框架用法
- Fresco图片加载框架使用
- Fresco图片框架初始化介绍
- 如何理解拓扑排序算法(转)
- 关键路径介绍(转)
- 浏览器加载Angular Web应用的方式
- 最短路径算法----Dijkstra (转)
- 最短路径算法----floyd(转)
- 引入Fresco框架
- DOM基础
- 用new关键字对一个String 变量赋值和用literal值直接赋值有什么不同(转)
- ionic3自定义tabs图标
- Python模块:time模块详解(转)
- HTTPS和HTTP的区别
- python标准输入
- 散列表(哈希表)工作原理 (转)
- 五大常用算法(转)