美文网首页Android开发移动开发iOS && Android
Android开发从放弃到捡起之Fresco

Android开发从放弃到捡起之Fresco

作者: 一个人开到荼蘼 | 来源:发表于2016-06-07 18:48 被阅读253次

    一:简介

    Fresco is a powerful system for displaying images in Android applications.

    Fresco takes care of image loading and display, so you don't have to. It will load images from the network, local storage, or local resources, and display a placeholder until the image has arrived. It has two levels of cache; one in memory and another in internal storage.

    In Android 4.x and lower, Fresco puts images in a special region of Android memory. This lets your application run faster - and suffer the dreadedOutOfMemoryErrormuch less often.

    Fresco also supports:

    streaming of progressive JPEGs

    display of animated GIFs and WebPs

    extensive customization of image loading and display

    and much more!

    强大的图片加载库,支持加载网络图片,本地内存图片或者资源图片,同时支持两级缓存,内存缓存和本地缓存

    在Android 4.x或者更低的系统中,Fresco会将图片放到特殊的Android内存区域,让程序运行更快

    Fresco同时还支持JPEG GIFs等等格式,有没有很兴奋,碉堡了

    先上下Github地址:

    https://github.com/facebook/fresco

    第一步:打开AndroidStudio项目的Module下的build.gradle下加入:

    dependencies{

    compile'com.facebook.fresco:fresco:0.9.0+'

    }

    在清单文件下加入网络权限:

    在onCreate中初始化

    Fresco.initialize(this);

    我们再layout中增加

    android:id="@+id/my_image_view"

    android:layout_width="100dp"

    android:layout_height="100dp"

    android:layout_centerInParent="true"

    app:placeholderImage="@mipmap/ic_hold"

    app:placeholderImageScaleType="center"

    app:failureImage="@mipmap/ic_failure02"

    app:failureImageScaleType="center"

    app:progressBarAutoRotateInterval="5000"

    app:progressBarImage="@mipmap/ic_progress"

    app:progressBarImageScaleType="center"

    app:roundAsCircle="true"

    app:roundedCornerRadius="50dp"

    app:roundingBorderColor="@android:color/holo_blue_light"

    app:roundingBorderWidth="10.0dip"/>

    然后我们来加载一张网络图:图片地址是下面这个

    https://github.com/white4hy/PopWin4Edit/blob/master/screenshots/device-2016-06-02-193415.png

    运行起来看一下:

    例子地址:

    https://github.com/white4hy/AndroidLearning

    相关文章

      网友评论

        本文标题:Android开发从放弃到捡起之Fresco

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