开始使用 Fresco
来源:互联网 发布:手机知乎怎么提问题 编辑:程序博客网 时间:2024/06/05 08:18
开始使用 Fresco
如果你仅仅是想简单下载一张网络图片,在下载完成之前,显示一张占位图,那么简单使用 SimpleDraweeView 即可。
在加载图片之前,你必须初始化Fresco
类。你只需要调用Fresco.initialize
一次即可完成初始化,在 Application
里面做这件事再适合不过了(如下面的代码),注意多次的调用初始化是无意义的。
12345678
[MyApplication.java]public class MyApplication extends Application {@Overridepublic void onCreate() {super.onCreate();Fresco.initialize(this);}}
做完上面的工作后,你需要在 AndroidManifest.xml
中指定你的 Application 类。为了下载网络图片,请确认你声明了网络请求的权限。
12345678910111213
<manifest ... > <uses-permission android:name="android.permission.INTERNET" /> <application ... android:label="@string/app_name" android:name=".MyApplication" > ... </application> ... </manifest>
在xml布局文件中, 加入命名空间:
123456
<!-- 其他元素--><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">
加入SimpleDraweeView
:
123456
<com.facebook.drawee.view.SimpleDraweeView android:id="@+id/my_image_view" android:layout_width="130dp" android:layout_height="130dp" fresco:placeholderImage="@drawable/my_drawable" />
开始加载图片:
123
Uri uri = Uri.parse("https://raw.githubusercontent.com/facebook/fresco/gh-pages/static/logo.png");SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);draweeView.setImageURI(uri);
剩下的,Fresco会替你完成:
- 显示占位图直到加载完成;
- 下载图片;
- 缓存图片;
- 图片不再显示时,从内存中移除;
等等等等。
点击打开链接 0 0
- 开始使用Fresco
- 开始使用 Fresco
- 开始使用 Fresco
- Fresco使用
- Fresco使用
- Fresco 使用
- Fresco使用
- Fresco使用
- Fresco初探-使用Fresco显示图片
- Fresco的使用
- Fresco使用总结
- Fresco 使用笔记
- Fresco使用注意点
- fresco使用文档地址
- fresco使用文档地址
- Fresco 基础使用
- fresco使用笔记
- Eclipse使用Fresco
- 跟:最大子序列问题
- AngularJS学习入手资料
- eclipse启动gc日志打印
- VS2005中添加lib文件的方法
- [LeetCode]473. Matchsticks to Square
- 开始使用 Fresco
- 回文数
- 【LeetCode】40. Combination Sum II
- 经济学十大原理
- ZooKeeper原理及其在Hadoop和HBase中的应用
- 本地jar包引入maven项目
- eclipse下如何打开ftl文件
- PLSQL Developer连接Oracle11g 64位数据库配置详解
- NOIP2009 潜伏者 Hankson的趣味题 最优贸易 靶形数独