Android uses a third-party framework fresco display Network pictures

Source: Internet
Author: User

Resource: Https://github.com/facebook/fresco] (Https://github.com/facebook/fresco

01: Advantages and Disadvantages:

Loading pictures for a long, recommended use, such as ListView entries in the picture.

02: Add Dependent Libraries: Add the following code in App/build.gradle, click Sync:

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

03. Layout:

<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    xmlns:tools=" Http://schemas.android.com/tools "    android:layout_width=" Match_parent    " android:layout_height= "Match_parent"    tools:context= "www.itcast.com.testfresco.MainActivity" ><!-- The wide height must be written dead--
<com.facebook.drawee.view.simpledraweeview
Android:id= "@+id/iv"
Android:layout_width= "200DP"
android:layout_height= "200DP"
Fresco:placeholderimage= "@mipmap/ic_launcher"/>
<button android:id= "@+id/btn" android:layout_centerinparent= "true" Android:layout_width= "Wrap_content" Android: layout_height= "Wrap_content" android:layout_alignparentbottom= "true" android:text= "Fresco Show Network Pictures"/> </ Relativelayout>

04. Access to the network of course adding permissions is essential:

<uses-permission android:name= "Android.permission.INTERNET"/>

05. To be aware of initialization:

Initializes the fresco.initialize (this) before the application is initialized or before the activity's Setcontentview () method;

06: Core Code:

public class Mainactivity extends Appcompatactivity implements View.onclicklistener {    private Simpledraweeview iv;< C1/>private Button btn;    Private String net_uri= "Http://img4.duitang.com/uploads/item/201412/11/20141211152834_eAfSi.jpeg";    @Override    protected void onCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        The initialized position        fresco.initialize (this);        Setcontentview (r.layout.activity_main);        Initview ();    }    private void Initview () {        IV = (Simpledraweeview) Findviewbyid (R.ID.IV);        BTN = (Button) Findviewbyid (R.ID.BTN);        Btn.setonclicklistener (this);    }    @Override public    void OnClick (View v) {        switch (V.getid ()) {case            r.id.btn:                Uri uri=uri.parse (net_ URI);                Iv.setimageuri (URI);                Break;}}}    

07: Picture Special Display Parameters:

Fresco:actualimagescaletype= how the "focuscrop"//Picture is scaled. Fresco:backgroundimage= "@color/blue"//background. Scaling is not supported. XML can only specify one background map. If you specify with Java code, you can specify multiple backgrounds, which are displayed in a similar way to framelayout.        Multiple backgrounds are stacked at one level in order. fresco:fadeduration= "300"///Fade picture time fresco:failureimage= "@drawable/error"//Picture loading failure display Picture Fresco:failureimag Escaletype= "Centerinside"////picture loading failed The zoom type of the picture displayed fresco:overlayimage= "@drawable/watermark"//cascade diagram, which is overlaid on top of the picture. Zooming is not supported. XM        L can only specify one sheet. If you specify with Java code, you can specify more than one, and the display is similar to framelayout, and multiple graphs cascade up one level at a sequential level. Fresco:placeholderimage= "@color/wait_color"//Picture loaded before loading successfully fresco:placeholderimagescaletype= "Fitcenter"//Picture load        The scale type of the bitmap that was displayed before success fresco:pressedstateoverlayimage= "@color/red"//Set the Cascade diagram under press State. Scaling is not supported. fresco:progressbarautorotateinterval= "1000"//progress bar picture rotation display length fresco:progressbarimage= "@drawable/progress_bar"//progress bar graph Slice fresco:progressbarimagescaletype= "centerinside"//progress bar Picture Zoom type fresco:retryimage= "@drawable/retrying"//When picture        When the load fails, the picture is displayed prompting the user to click Reload pictureFresco:retryimagescaletype= "Centercrop"//Hint Picture zoom type fresco:roundascircle= "false"//show circular picture Fresco:roundbott        Omleft= the "false"///Roundedcornerradius property is set, the four corners will have rounded corners, and if the lower left corner is not set to false.        Fresco:roundbottomright= the "true"///Roundedcornerradius property is set, the four corners have rounded corners and if the lower-right corner does not need to be set to false.        Fresco:roundtopleft= the "true"///Roundedcornerradius property is set, the four corners will have rounded corners, and if the upper-left corner does not need to be set to false.        Fresco:roundtopright= the "false"///Roundedcornerradius property is set, the four corners will have rounded corners and if the upper-right corner does not need to be set to false. Fresco:roundwithoverlaycolor= "@color/corner_color"//sets the color of the vacated area after the picture fillet. As in the red part of the example figure fresco:roundedcornerradius= "1DP"/        /Set the angle of the picture fillet, the four corners of the property will take effect after setting the fresco:roundingbordercolor= "@color/border_color"//Set the color of the border after the fillet. Fresco:roundingborderwidth= "2DP"/>//After setting the fillet, the width height of the outer border

08. The picture shows the Java code in particular:

Genericdraweehierarchy hierarchy = Genericdraweehierarchybuilder                . newinstance (Getresources ())                . Setretryimage (Getresources (). getdrawable (R.mipmap.ic_launcher))                . Build ();        Imageivew.sethierarchy (hierarchy);

09. Progressive Display of the picture (the number of downloads to show how much, not before the download is blurred):

 /* Progressive display picture Progressivejpegconfig Pjpegconfig = new Progressivejpegconfig () {@Override                        Returns the next number of scans to decode public int getnextscannumbertodecode (int scannumber) {                    return ScanNumber + 2;                        }//Determines how many times the image after the scan can begin to show public qualityinfo getqualityinfo (int scannumber) {                        Boolean Isgoodenough = (scannumber >= 5);                    Return Immutablequalityinfo.of (ScanNumber, Isgoodenough, false);                }                };                        Imagepipelineconfig configuring how to load images imagepipelineconfig config = Imagepipelineconfig.newbuilder (this)                . Setprogressivejpegconfig (Pjpegconfig). build (); explicitly specifies that a progressive JPEG picture is allowed to load imagerequest request = Imagerequestbuilder. Newbuilderwithsou Rce (URI).Setprogressiverenderingenabled (True). Build ();                        Build the Draweecontroller Draweecontroller controller = fresco.newdraweecontrollerbuilder () used to display the image                        . Setimagerequest (Request). Setoldcontroller (Iv.getcontroller ())                . build ();                Iv.setcontroller (Controller); */

10. Display GIF pictures:

/* Displays a GIF picture. Fresco supports animated pictures in GIF and WebP formats. If you want the picture to be played automatically after it is downloaded, and when the view is removed from the screen, simply set the                uri urlgif = URI in the image request . Parse ("http://img0.imgtn.bdimg.com/it/u=4040253614,2927360696&fm=21&gp=0.jpg");                Draweecontroller controller = Fresco.newdraweecontrollerbuilder ()                        . Seturi (urlgif)                        . Setautoplayanimations ( true)                        . Build ();                Iv.setcontroller (Controller);                */

11: Code Resources:

http://download.csdn.net/detail/tom91/9631011

Android uses a third-party framework fresco display Network pictures

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.