第一 Fresco源码地址:http://fresco-cn.org/
第二 在你的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' 第三 使用Fresco必须初始化
public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); Fresco.initialize(this); } }第四 需要在
AndroidManifest.xml
添加以下权限和生命Application
<manifest ... > <uses-permission android:name="android.permission.INTERNET" /> <application ... android:label="@string/app_name" android:name=".MyApplication" > ... </application> ... </manifest>
第五 加入Fresco的命名空间
<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"> 第六 添加Fresco自己的控件<com.facebook.drawee.view.SimpleDraweeView android:id="@+id/my_image_view" android:layout_width="130dp" android:layout_height="130dp" fresco:placeholderImage="@drawable/my_drawable" /> 第七 需要加载图片的地方直接引用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的优缺点 |