Android开发从放弃到捡起之Fresco

一:简介

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);

Android开发从放弃到捡起之Fresco_第1张图片

我们再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"/>


Android开发从放弃到捡起之Fresco_第2张图片

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

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

Android开发从放弃到捡起之Fresco_第3张图片

运行起来看一下:


例子地址:

https://github.com/white4hy/AndroidLearning

你可能感兴趣的:(Android开发从放弃到捡起之Fresco)