Fresco load static pictures and dynamic pictures examples

Source: Internet
Author: User
Tags xmlns

Before writing the project used Universalimageloader,picasso and other pictures to load the frame, found that they do not support the loading GIF map, and then learned that the fresco picture loading frame, it can load GIF animated diagram, summed up its simple use.

First, the Android Studio developer adds a line of code to the dependencies:

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

Layout:

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
xmlns:fresco= "Http://schemas.android.com/apk/res-auto"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >

<!--does not support wrap_content-->
<com.facebook.drawee.view.simpledraweeview
Android:id= "@+id/user_avator1"
Android:layout_width= "100DP"
android:layout_height= "100DP"
Fresco:placeholderimage= "@mipmap/ic_launcher"/>

<!--fresco:placeholderimage= "@mipmap/ic_launcher" is a placeholder picture-->

<com.facebook.drawee.view.simpledraweeview
Android:id= "@+id/user_avator2"
Android:layout_width= "100DP"
android:layout_height= "100DP"
Fresco:placeholderimage= "@mipmap/ic_launcher"/>
</LinearLayout>

Activity:

Import android.app.Activity;
Import Android.net.Uri;
Import Android.os.Bundle;
Import Com.facebook.drawee.backends.pipeline.Fresco;
Import Com.facebook.drawee.interfaces.DraweeController;
Import Com.facebook.drawee.view.SimpleDraweeView;


public class Mainactivity extends activity {

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Fresco.initialize (mainactivity.this);//Registered, before Setcontentview.
Setcontentview (R.layout.activity_main);
Simpledraweeview simpleDraweeView1 = (simpledraweeview) Findviewbyid (R.id.user_avator1);
Simpledraweeview simpleDraweeView2 = (simpledraweeview) Findviewbyid (R.ID.USER_AVATOR2);
Uri uri = uri.parse ("Yun_qi_img/468f0fc71e49479bf021c64cefee2882.gif");
Load a static picture
Simpledraweeview1.setimageuri (URI);
Load dynamic Picture
Draweecontroller controller = Fresco.newdraweecontrollerbuilder (). Seturi (URI). Setautoplayanimations (True). Build () ;
Simpledraweeview2.setcontroller (Controller);

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.