美文网首页
Fresco 使用

Fresco 使用

作者: 路Promenade | 来源:发表于2016-12-07 14:22 被阅读179次

    Fresco 官网:http://fresco-cn.org/
    fresco demo:https://github.com/liaohuqiu/fresco-demo-for-gradle
    Fresco引起的在arm64位机器上找不到对应的so库:http://blog.csdn.net/it_talk/article/details/50835595

    Fresco 使用

    加载网络图片简单步骤

    添加依赖

    compile 'com.facebook.fresco:fresco:0.14.1'
    

    在 Application 中初始化

    [MyApplication.java]
    public class MyApplication extends Application {
        @Override
        public void onCreate() {
            super.onCreate();
            Fresco.initialize(this);
        }
    }
    

    在 xml 布局文件中,加入命名空间:

    <!-- 其他元素-->
    <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

    <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 的绝对 url

    raw 路径示例:

    "res://com.xxx.yy/"+R.raw.web_loading
    

    正式打包时候遇到的问题

    不同引用库里jar的重复引用。

    Error:Execution failed for task ':qspLauncher:transformClassesAndResourcesWithProguardForOnlineRelease'.
    > java.io.IOException: Can't write [D:\qsp_release\qspLauncher\build\intermediates\transforms\proguard\online\release\jars\3\1f\main.jar] (Can't read [D:\qsp_release\qspLauncher\build\intermediates\exploded-aar\com.android.support\support-core-utils\24.2.1\jars\libs\internal_impl-24.2.1.jar(;;;;;;**.class)] (Duplicate zip entry [internal_impl-24.2.1.jar:android/support/v4/graphics/drawable/RoundedBitmapDrawable.class]))
    

    解决办法:
    修改导入的fresco 的版本compile ('com.facebook.fresco:fresco:0.6.0+')

    
    
    
    
    
    
    
    

    相关文章

      网友评论

          本文标题:Fresco 使用

          本文链接:https://www.haomeiwen.com/subject/kdyvpttx.html