Fresco is a framework used by facebook to manage Android image loading, Fresco is obviously similar to the structure of MVC, DraweeView as the View layer, is the real rendering layer of the image, DraweeHierarchy is responsible for component maintenance of the final Drawable object, which is equivalent to M, and DraweeController is equivalent to Controller, It is responsible for the data processing of images, and the default implementation is ImagePipeline, which has two levels of memory cache and one level of disk cache.
Simple to use:
Add the required dependencies:
implementation 'com.facebook.fresco:fresco:0.12.0'
- Other non-essential dependencies:
dependencies {// When machines on API < 14 support WebP, you need to add implementation ‘com.facebook.fresco:animated-base-support:0.12.0’ // Support GIF GIFs, you need to add implementation ‘com.facebook.fresco:animated-gif.} :0.12.0’// Support WebP (static image + animated image), you need to add implementation ‘com.facebook.fresco:animated-webp:0.12.0’implementation ‘com.facebook.fresco:webpsupport:0.12.0’// Only support WebP static image, Need to add implementation ‘com.facebook.fresco:webpsupport:0.12.0’}
Initialize the Fresco class:
[MyApplication.java]public class MyApplication extends Application {@Overridepublic void onCreate() {super.onCreate(); Fresco.initialize(this); }}
To add network request permissions to the AndroidManifest.xml:
<uses-permission android:name=”android.permission.INTERNET” />
Add the SimpleDraweeView component to the xml layout file:
<com.facebook.drawee.view.SimpleDraweeView android:id="@+id/my_image_view" android:layout_width="130dp" android:layout_height="130dp" fresco:placeholderImage="@drawable/my_drawable" />
- Start loading the image:
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);
The above is the simple use of Fresco, of course, Fresco has other advanced functions, which can meet the needs of daily development, interested students can learn about it.