Android 图片加载利器---Fresco基本用法

Fresco是Facebook最新推出的一款用于Android应用中展示图片的强大图片库,可以从网络、本地存储和本地资源中加载图片。相对于ImageLoader,拥有更快的图片下载速度以及可以加载和显示gif图等诸多优势,是个很好的图片框架;

1.添加依赖

compile 'com.facebook.fresco:fresco:0.13.0'
//记得必须初始化,在application或setContentView前面;

2.布局文件(Fresco是基于组件的)

<com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/imageshow"
        android:layout_width="300dp"
        android:layout_height="400dp"
        android:layout_centerInParent="true"
        fresco:fadeDuration="300"
        fresco:actualImageScaleType="focusCrop"
        fresco:placeholderImage="@color/wait_color"
        fresco:placeholderImageScaleType="fitCenter"
        fresco:failureImage="@mipmap/ic_launcher"
        fresco:failureImageScaleType="centerInside"
        fresco:retryImage="@mipmap/axc_icon"
        fresco:retryImageScaleType="centerCrop"
        fresco:progressBarImage="@mipmap/loading_logo"
        fresco:progressBarImageScaleType="centerInside"
        fresco:progressBarAutoRotateInterval="1000"
        fresco:backgroundImage="@color/blue"
        fresco:overlayImage="@color/v1_style_yellow"
        fresco:pressedStateOverlayImage="@color/red"
        fresco:roundAsCircle="false"
        fresco:roundedCornerRadius="1dp"
        fresco:roundTopLeft="true"
        fresco:roundTopRight="false"
        fresco:roundBottomLeft="false"
        fresco:roundBottomRight="true"
        fresco:roundWithOverlayColor="@color/corner_color"
        fresco:roundingBorderWidth="2dp"
        fresco:roundingBorderColor="@color/border_color"
        />

属性介绍:

名称  描述
fadeDuration            图片从无到有的显示时间
actualImageScaleType    图片适配类型,同scaleType,但有区别
placeholderImage    占位图片
placeholderImageScaleType   占位图片的适配类型
failureImage    下载失败之后显示的图片
failureImageScaleType   下载失败之后图片的适配类型
retryImage  加载失败,提示用户点击重新加载的图片(会覆盖failureImage的图片)
retryImageScaleType     图片的适配类型
progressBarImage    提示用户正在加载,和加载进度无关
progressBarImageScaleType   图片的适配类型
progressBarAutoRotateInterval   加载图片的旋转频率
backgroundImage     背景图片,最底层的图层
overlayImage    叠加图
pressedStateOverlayImage    状态迭加图
roundAsCircle   是否显示圆形
roundedCornerRadius     圆角的半径
roundTopLeft/Right/Top/Bottom   是否支持圆角
roundWithOverlayColor   下载成功之前显示的图片
roundingBorderWidth     边框宽度
roundingBorderColor     边框的颜色
viewAspectRatio     宽高比
Uri uri = Uri.parse("url");  
SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.my_image_view);  
draweeView.setImageURI(uri);  

将到这里在项目中基本就可以解决绝大多数问题了;下面就是硬菜了;
注意:fresco不支持wrap_content;还需要初始化,可在application或setContentView方法前面出初始化;

3.fresco加载本地图片

//加载mipmap下的一张图片,res://是固定写法,如果非要问为什么,请去问Facebook的工程师,注意id是这样写的: 如: R.mipmap.ic_laucher;
public static void loadResPic(Context context, SimpleDraweeView simpleDraweeView, int id) {
Uri uri = Uri.parse(“res://” +
context.getPackageName() +
“/” + id);
simpleDraweeView.setImageURI(uri);
}

硬菜一: (想了想,还是算了吧, 后面的菜比较多,下篇博客针对性的bb)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值