zoukankan      html  css  js  c++  java
  • Fresco的使用<一>

    目录(?)[+]

    引入Fresco

    dependencies {
      // 添加依赖
      compile 'com.facebook.fresco:fresco:0.13.0'
    }

    开始使用 Fresco

    1.进行全局初始化,添加网络权限

    // 需要在 AndroidManifest.xml 中指定你的 Application 类
    // android:name=".MyApplication"
    public class MyApplication extends Application {
        @Override
        public void onCreate() {
            super.onCreate();
            // onCreate()进行初始化
            Fresco.initialize(this);
        }
    }

    2.布局

    <!-- 在xml布局文件中, 加入命名空间:-->
    xmlns:fresco="http://schemas.android.com/apk/res-auto"

    2.1.使用控件SimpleDraweeView(不使用ImageView)

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/my_image_view"
        android:layout_width="130dp"
        android:layout_height="130dp"
        fresco:placeholderImage="@drawable/my_drawable"
      />

    2.2.注意:Drawees 不支持 wrap_content 属性,只能使用固定宽高(xx dp,match_parent),如果想使用wrap_content需要配合viewAspectRatio属性来使用。

    <!-- placeholderImage:占位图
         placeholderImageScaleType:占位图缩放类型
         viewAspectRatio:固定宽高比例
         如果希望图片以特定的宽高比例显示,例如 1:1,
         fresco:viewAspectRatio="1"
         如果是 4:3 则改为1.33
         也可以在代码中指定显示比例:
         mSimpleDraweeView.setAspectRatio(1.33f);  -->
    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/my_image_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        fresco:placeholderImage="@drawable/my_drawable"
        fresco:placeholderImageScaleType="fitXY"
        fresco:viewAspectRatio="1"
      />

    3.开始加载图片:

    Uri uri = Uri.parse("https://www.baidu.com/img/bd_logo1.png");
    SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);
    draweeView.setImageURI(uri);

    4.剩下的,Fresco会替你完成:

    • 显示占位图直到加载完成;
    • 下载图片;
    • 缓存图片;
    • 图片不再显示时,从内存中移除;
    • 等等等等。
  • 相关阅读:
    微信支付开发
    dz插件开发(一) 从常用的常量 变量 函数开始
    收集bootstrap的几个常用用法---tooltip提示框
    ucenter接口
    php防止表单重复提交
    支付宝接口 CI上集成
    telnet模拟post 调试的时候很好用
    __call 实现函数方法不同参数个数的重载
    微赞的分页
    结合微赞发布家和小程序流程
  • 原文地址:https://www.cnblogs.com/ldq2016/p/6646796.html
Copyright © 2011-2022 走看看