关于Fresco的

来源:互联网 发布:java file.getlength 编辑:程序博客网 时间:2024/06/07 08:28

其实关于fresco的使用还是比较简单的。不管要不要用,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'
然后在xml中,哪里需要使用图片加载的就把这个fresco给放上去。

<com.facebook.drawee.view.SimpleDraweeView    android:id="@+id/my_test_view"    android:layout_width="100dp"    android:layout_height="100dp"    />

唯一提一下的是,facebook的fresco的时候碰到一个坑。错误日志如下:

java.lang.RuntimeException: 

Unable to start activity ComponentInfo{com.---.---.---/com.---.---.---.MainActivity}: 

android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class com.facebook.drawee.view.SimpleDraweeView

关于这个错误,我觉得可能是fresco文档写的不够好,虽然文档中说明了在onCreate的时候初始化fresco。但是初始化必须在setContentView之前。

如果出现这个错误,换个顺序就能解决。但是如果没注意到它,估计也让你觉得很懵逼。别的没什么好强调的,fresco还是挺好用的。

super.onCreate(savedInstanceState);Fresco.initialize(this);setContentView(R.layout.activity_main);

再补充一点:

在使用fresco时,在xml中调用fresco的方法时,如果出现

Error:(9) Error parsing XML: unbound prefix

这个和我们调用android:其实时一样的。安卓xml文件头部我们会声明

xmlns:android="http://schemas.android.com/apk/res/android"

同样fresco也要声明,在xml的上增加下面这行代码就搞定了

xmlns:fresco="http://schemas.android.com/apk/res-auto"

原创粉丝点击