修正一下,之前的都是乱码,编辑器不好用.差评~!
1先将资源库文件导入到你的ecplise中, 我上传的资源地址:资源地址
中文的Fresco文档,建议大家提早转AS开发,并且有问题的话Ecplice直接去github问,毕竟人家开发都是用AS开发的.之前这个Eclipse 有问题,我也跑去问了....
中文文档地址: Fresco文档地址
因为之前我下载的官方支持的版本报
Could not find class 'com.facebook.imagepipeline.producers.DiskCacheProducer$1', referenced from method
这个错误,上面我上传的包已经修复了这个问题,我已经测试过了.
1.简单的使用方式
第一步要添加联网权限
<uses-permission android:name="android.permission.INTERNET"/>
第二步 ,这个初始化的声明要放在你的setContentView之前之前,在这个之前
// 我自己是放在自定义的application的子类当中,这个类是当程序开始加载,页面都没开始加载就创建了.所以起来的很早
Fresco.initialize(getApplicationContext());
第三步 记得在你的layout根布局下要声明下这个命名空间,要在根目录下.
xmlns:fresco="http://schemas.android.com/apk/res-auto"
第四步 这个就是我们要用的控件了. 使用必须要用他的控件,不想ImageLoader那样,使用自己的控件,然后对图片进行缓存.当然你也可以动态的在代码中进行控件的初始化操作.直接new出来这个控件也是可以的
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/facebook_show"
android:layout_width="match_parent"
android:layout_height="200dp"
fresco:placeholderImageScaleType="fitCenter"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_margin="10dp"
android:layout_marginTop="10dp">
</com.facebook.drawee.view.SimpleDraweeView>
第五步 在代码中的使用
根据官方文档,这货uri是支持四种的,并且只能在水管中传入照片流,其它的一起流都会报错的
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/facebook_show"
android:layout_width="match_parent"
android:layout_height="200dp"
fresco:placeholderImageScaleType="fitCenter"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_margin="10dp"
android:layout_marginTop="10dp">
</com.facebook.drawee.view.SimpleDraweeView>
特别注意:Fresco 不支持 相对路径的URI. 所有的URI都必须是绝对路径,并且带上该URI的scheme。
如下:
类型 Scheme 示例
远程图片 http://, https:// HttpURLConnection 或者参考 使用其他网络加载方案
本地文件 file:// FileInputStream
Content provider content:// ContentResolver
asset目录下的资源 asset:// AssetManager
res目录下的资源 res:// Resources.openRawResource
ps:我在使用asset的时候,使用的asset:/// 才行,不要问我为什么,我不知道.