Hi Everybody today to play a very cool control fresco in the end how cool
You'll see.
First of all, let's see Fresco is a god horse.
Https://github.com/facebook/fresco This is a fresco official Gifhub website for http://frescolib.org/
This site is an English-language site for English is not very proficient in children's shoes it's okay because this is a picture loading library we say the traditional loading library
From writing a bitmap class tool to a soft reference to imageloader it's all about solving an oom problem, but there's a problem.
They're not going to be able to dynamically load or load some GIF or describe a picture. Typically, you write a custom roundimage
Then go to XXX or use a library like Gifimageview or Rounndeimageview to add a library after all, your project will be getting bloated.
But fresco solved the problems we had before, and the other thing is that we are loading the network, especially when the internet is slow, we find that the pictures are not a bit
Loaded out and need a little bit of gradual step this in the past the plug-in is rarely done, and fresco can really realize the Benga side of the need to see
Meet the needs of most obsessive-compulsive disorder (like me) people.
Come on, fresco, let's go see the Official guide.
Http://frescolib.org/docs/index.html
1 Register your manifest file plus a permission to access the network
Http://frescolib.org/docs/index.html, there's nothing to say, just add one.
2 because fresco requires an initialization process, the initialization method needs to be called
Fresco.initialize (context);
Of course, if you write it directly in Actvity,
Fresco.initialize (this); It's understandable.
This time someone might ask me if there's no fresco in the project.
This official GitHub provides us with a way to import
Since I'm using studio, it's easy to do this, given the Gradle project.
Just add a line of code to the Build.gradle
'com.facebook.fresco:fresco:0.1.0+'
You can see that this library is still in a very new version, so the future of this thing is limitless.
You need to use a proxy here or your project may not be able to download this library
3 we're done. Add a layout file and a custom view to use
Look at the code.
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "xmlns:fresco=" http://schemas.android.com/apk/ Res-auto "android:layout_height=" Match_parent "tools:context=". Mainactivity "> <textview android:layout_centerhorizontal=" true "android:id=" @+id/title "Android oid:text= "Fresco pic" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:textS Ize= "20SP" android:textcolor= "#000000"/> <linearlayout android:layout_below= "@id/title" Android:layout_width= "Match_parent" android:layout_height= "match_parent" android:orientation= "vertical" Android:gravity= "Center_horizontal" android:background= "#649FEF" > <com.facebook.drawee.view . Simpledraweeview android:id= "@+id/frsco_img1" android:layout_width= "200DP" Android:layout_height= "0DP" android:layout_weight= "1" fresco:roundedcornerradius= "5DP" fresco:roundbottomleft= "FA LSE "fresco:roundbottomright=" false "fresco:roundwithoverlaycolor=" #333333 "Fresco:roundingborderwidt H= "1DP" fresco:roundingbordercolor= "#222222"/> <com.facebook.drawee.view.simpledraweeview A Ndroid:id= "@+id/frsco_img2" android:layout_width= "200DP" android:layout_height= "0DP" Android:layout_w eight= "1" fresco:roundedcornerradius= "5DP" fresco:roundbottomleft= "false" fresco:roundbottomright= "FA LSE "fresco:roundwithoverlaycolor=" #333333 "fresco:roundingborderwidth=" 10DP "Fresco:roundingborderco Lor= "#33CC5B" android:layout_centerhorizontal= "true"/> <com.facebook.drawee.view.simpledraweeview Android:id= "@+id/frsco_img3" android:layout_width= "200DP" android:layout_height= "0DP" Android: layout_weight= "1" fresco:roundedcornerradius= "5DP" fresco:roundbottomleft= "false" fresco:roundbottomright= "false" Fres Co:roundwithoverlaycolor= "#F0E511" fresco:roundingborderwidth= "5DP" fresco:roundingbordercolor= "#FC6853" Android:layout_centerhorizontal= "true"/> </LinearLayout></RelativeLayout>
Three of these simpledraweeview are added here for demonstration purposes.
And then there's a namespace so you can use some fresco to give you some of the properties
Like this one.
Fresco:roundwithoverlaycolor= "#333333"
Set the color of your overlays there's a lot more to this one. You can try it yourself.
All right, look at the code.
public class Mainactivity extends Activity implements View.ontouchlistener {private Simpledraweeview Msimpledraweeview ; Private Simpledraweeview mSimpleDraweeView2; Private Simpledraweeview mSimpleDraweeView3; Private String ImageUri1 = "http://img.ptcms.csdn.net/article/201503/30/5519091be9a85_middle.jpg?_=30474"; Private String ImageUri2 = "Http://ww1.sinaimg.cn/mw600/6345d84ejw1dvxp9dioykg.gif"; Private String ImageUri3 = "Http://p5.qhimg.com/t01d0e0384b952ed7e8.gif"; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Fresco.initialize (this); Setcontentview (R.layout.activity_main); SetImage (); }/** * Set auto play picture three */private void setimage () {uri uri = Uri.parse (IMAGEURI1); Uri uri2 = Uri.parse (IMAGEURI2); Uri Uri3 = Uri.parse (IMAGEURI3); Msimpledraweeview = (Simpledraweeview) Findviewbyid (R.ID.FRSCO_IMG1); Draweecontroller DraweecoNtroller1 = Fresco.newdraweecontrollerbuilder (). Seturi (URI). Setautoplayanimations (True). Build (); Msimpledraweeview.setcontroller (DraweeController1); Msimpledraweeview.setontouchlistener (this);//Uri Uri2 = Uri.parse (IMAGEURI2); Draweecontroller draweeController2 = Fresco.newdraweecontrollerbuilder (). Seturi (Uri2). Setautoplayanimations (True) . build (); MSimpleDraweeView2 = (Simpledraweeview) Findviewbyid (R.ID.FRSCO_IMG2); Msimpledraweeview2.setcontroller (DRAWEECONTROLLER2); Roundingparams mRoundParams2 = Msimpledraweeview2.gethierarchy (). Getroundingparams (); Mroundparams2.setroundascircle (TRUE); Msimpledraweeview2.gethierarchy (). Setroundingparams (MROUNDPARAMS2); Draweecontroller DraweeController3 = Fresco.newdraweecontrollerbuilder (). Seturi (Uri3). Setautoplayanimations (True) . build (); MSIMPLEDRAWEEVIEW3 = (Simpledraweeview) Findviewbyid (R.ID.FRSCO_IMG3); Msimpledraweeview3.setcontroller (DRAWEECONTROLLER3); Roundingparams mRoundParams3 = Msimpledraweeview3.gethierarchy (). Getroundingparams (); Mroundparams3.setroundascircle (TRUE); Msimpledraweeview3.gethierarchy (). Setroundingparams (MROUNDPARAMS3); } @Override public boolean OnTouch (View V, motionevent event) {switch (event.getaction ()) {case M OtionEvent.ACTION_DOWN:mSimpleDraweeView.setColorFilter (Color.gray, PorterDuff.Mode.MULTIPLY); return true;//break; Case MotionEvent.ACTION_UP:mSimpleDraweeView.clearColorFilter (); return true;//break; } return Super.ontouchevent (event); }}
Here the code is like this
1 we use a static diagram to first find this control and then use the URI class to encapsulate a corresponding link
2 Draweecontroller The function of this class is to dynamically play your GIF or some dynamic graph of course it's still listening.
3 The use of the circular chart is required to use the Facebook Roundparmas this class
And the method of obtaining this class has been written very clearly.
Look down.
OK, so much for this time, everybody.
About picture loading very cool a three-party control fresco