In the previous internship in Zhuo New Technology Co., Ltd., in their love of the headlines app, when the picture asynchronous loading and the sliding of the ListView, there will always be a lag,
This is because the picture of the cache does not have enough in place, with the help of project supervision, there is the use of xutils frame picture loading, but also use imageloader to achieve,
In today's brother Wai public number Gank to a current most powerful picture loading frame--fresco.
Fresco is an open-source framework released by Facebook, claiming to be the strongest Android image loading library of all time, with a very good memory performance, given the confidence that
For some of the introduction of fresco, not much to say, if you are interested will definitely go to the Internet to find some relevant information, suggest you to the official website to view: http://frescolib.org/.
Of course, the great God of the domestic also on this site has been translated, if your English level compare catch urgent, please to http://fresco-cn.org/to observe, but still suggest to the official website,
Because you do not know when there will be updates, third-party documents will not be timely.
Well, say no more, I believe you love Android, and I, like, can't wait.
1) Add dependent libraries.
The current version of Git is 0.11.0
dependencies { compile filetree (include: [' *.jar '], dir: ' Libs ') testcompile ' junit:junit:4.12 ' compile ' com.android.support:appcompat-v7:23.4.0 ' compile ' com.facebook.fresco:fresco:0.11.0 '}
After introduction andriod studio will automatically load the remote library, if there is no VPN, it may be a little longer.
For the introduction of Eclipse, there is not much to say, more trouble, and you will abandon the super-good pro-son studio?
2) Then if you are using fresco multiple times, it is recommended to initialize it in application, and if it is only written to play, initialize it before the app calls Setcontentview ():
Package Com.example.nanchen.imageloadfrescodemo;import Android.app.application;import com.facebook.drawee.backends.pipeline.fresco;/** * Created by Southern dust on 2016/7/11. */public class MyApplication extends application { @Override public void OnCreate () { super.oncreate (); Fresco.initialize (this);} }
3) because I am loading a network image here, so to get network permissions
<uses-permission android:name= "Android.permission.INTERNET"/>
4) Use the People's framework is to follow the requirements of others are not, so the control name, namespace to listen to others
Fresco is different from several other picture loading libraries, which are based on custom controls, to use control Simpledraweeview to display pictures,
Note that the control does not support wide height and is set to Wrap_content, and the default force setting is wide, otherwise the picture is not displayed
<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android = "Http://schemas.android.com/apk/res/android" xmlns:tools= "http://schemas.android.com/tools" xmlns:fresco= "http ://schemas.android.com/apk/res-auto "android:layout_width=" match_parent "android:layout_height=" match_parent "too ls:context= "Com.example.nanchen.imageloadfrescodemo.MainActivity" > <!--< com.facebook.drawee.view.simpledraweeview--> <!--android:layout_width= "50DP"-<!--Android:layo ut_height= "50DP"-<!--android:id= "@+id/main_simple_drawee_view"-<!--Fresco:placeholderimage = "@mipmap/ic_launcher"/>--> <com.facebook.drawee.view.simpledraweeview android:layout_width= "400DP" android:layout_height= "Match_parent" android:id= "@+id/main_simple_drawee_view" fresco:placeholderimage= " @mipmap/ic_launcher "/></RELATIVELAYOUT>
5) Loading the image display in activity, Fresco does not support the URI of the relative path. All URIs must be absolute paths, with the scheme of the URI.
Package Com.example.nanchen.imageloadfrescodemo;import Android.net.uri;import Android.os.bundle;import Android.support.v7.app.appcompatactivity;import Com.facebook.drawee.backends.pipeline.fresco;import Com.facebook.drawee.interfaces.draweecontroller;import Com.facebook.drawee.view.simpledraweeview;public Class Mainactivity extends Appcompatactivity {private Simpledraweeview SDV; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);//Fres Co.initialize (this);//fresco initialization, must be called before Setcontentview Setcontentview (R.layout.activity_main); SDV = (Simpledraweeview) Findviewbyid (R.id.main_simple_drawee_view); Uri uri = uri.parse ("http://dynamic-image.yesky.com/740x-/uploadImages/2015/163/50/690V3VHW0P77.jpg");//Sdv.setim Ageuri (URI); Draweecontroller controller = Fresco.newdraweecontrollerbuilder (). Seturi (URI). Setautoplaya Nimations (True). Build (); Sdv.setcontroller (Controller); }}
The results are as follows:
- Drawee supports the following properties:
fresco:fadeduration= "300"//Fade duration fresco:actualimagescaletype= "Focuscrop"//The zoom type of the actual image fresco: Placeholderimage= "@color/wait_color"//Placeholder bitmap fresco:placeholderimagescaletype= "Fitcenter"//The zoom type of the bitmap fresco:f Ailureimage= "@drawable/error"//download failure display picture fresco:failureimagescaletype= "centerinside"//Failure graph Zoom Type FRESCO:RETR Yimage= "@drawable/retrying"//image loading fails to display, prompting the user to click Reload, repeated loading 4 times or not loaded out when the picture is displayed Failureimage Fresco:retryimagesca Letype= "Centercrop"//Reload Picture Zoom type fresco:progressbarimage= "@drawable/progress_bar"//progress bar picture FRESCO:PROGRESSBA Rimagescaletype= "Centerinside" fresco:progressbarautorotateinterval= "1000"//Progress Chart automatic rotation interval (in milliseconds ms) fre Sco:backgroundimage= "@color/blue"//Background picture, here the background picture is first drawn fresco:overlayimage= "@drawable/watermark"//settings Overlay, you can only set an overlay in the XML, if more than one picture, you need to set in the Java code oh fresco:pressedstateoverlayimage= "@color/red"//Set the click-State of the overlay map Fresco:roundascircle= "false"//set to circular figure fresco:roundedcornerradius= "1DP"//Fillet radius fresco:roundtopleft= "true"///the upper-left corner is rounded fre Sco:roundtopright= "false" fresco:roundbottomleft= "false" fresco:roundbottomright= "true" FRESCO:ROUNDW Ithoverlaycolor= "@color/corner_color" fresco:roundingborderwidth= "2DP"//Border Width fresco:roundingbordercolor= "@ Color/border_color "//Border color
The imagescaletype above has some of the following scaling types:
Type |
Describe |
Center |
Center, No Zoom |
Centercrop |
To keep the aspect ratio smaller or larger, both sides are greater than or equal to the boundary, and the width and height fit the display boundary, centered display |
Focuscrop |
With Centercrop, but the center point is not the midpoint, but a specified point |
Centerinside |
Zoom the picture so that both sides are within the display boundary and centered. Unlike fitcenter, images are not magnified. If the dimension is greater than the display boundary, keep the picture wide and high. |
Fitcenter |
Maintain the aspect ratio, zoom out or zoom in, so that the picture is completely displayed within the display boundary, and wide or high fits the display boundary, centered. |
Fitstart |
Ditto, but not centered, and aligns to the top left of the display boundary. |
Fitend |
With Fitcenter, but not centered, and the display boundary is aligned to the right bottom. |
Fitxy |
Do not save the aspect ratio, fill the display boundary. |
None |
If you want to use the tile mode display, you need to set to none |
Dotou Request
Sometimes need to load a lot of pictures, this time if the network situation is not very good situation, has been shown to occupy the bitmap, the experience is not very good, we can first display a low-resolution picture, wait until the large image loading completed, after the display of real pictures.
Draweecontroller controller = Fresco.newdraweecontrollerbuilder () . Setlowresimagerequest (Imagerequest.fromuri (Lowresuri)) . Setimagerequest (Imagerequest.fromuri (Highresuri)) . Setoldcontroller (Draweeview.getcontroller ()) . Build ();d Raweeview.setcontroller (Controller);
Of course, if you want to listen to the loading process, add a Controllerlisten
Write a listener monitor picture load Controllerlistener listener = new Basecontrollerlistener () {/** * when figure The method that will execute when the tablet is loaded successfully * @param ID * @param imageinfo * @param animatable * * @Override public void Onfinalimageset (String ID, Object imageinfo, animatable animatable) { Super.onfinalimageset (ID, imageinfo, animatable); }/** * The method called when the picture loading failed * @param ID * @param throwable */ @Override public void OnFailure (String ID, throwable throwable) {super.onfailure (ID, throwab Le); }/** * If the image is using progressive, this method will be callback * @param ID * @param throwable */ @Override public void onintermediateimagefailed (String ID, throwable throwable) {sup er.onintermediateimagefailed (ID, throwable); } }; Draweecontroller controller = Fresco.newdraweecontrollerbuilder (). Seturi (URI). Setaut Oplayanimations (True). Setcontrollerlistener (Listener). build (); Sdv.setcontroller (Controller);
Powerful picture loading frame fresco for use