I. Introduction to the glide picture loading framework
Google 2014 Developer Forum on the introduction of the picture loading framework, it allows us to deal with whether it is a network download pictures or local pictures, reduce a lot of work,
Second, the development steps:
1. Add a link library
Compile ' com.github.bumptech.glide:glide:3.7.0 '
2, code writing, the main features
Glide.with (context). Load (imgurl) . Dontanimate (). Skipmemorycache (True) . Diskcachestrategy ( Diskcachestrategy.all) . Placeholder (r.drawable.head_default). error (R.drawable.head_default). into (ImageView);
When loading a picture on the network, Imgurl: The address of the picture
When a local picture is loaded
Glide.with (context) //. Load (Imgurl) . Load (Uri.fromfile (new File (Imgurl)))
"When loading pictures on the network, due to network reasons, the picture is not displayed in time, need to display a waiting picture
. Placeholder (R.drawable.head_default)
When a picture fails to load for various reasons, the picture is displayed
. Error (R.drawable.head_default)
"Sets the animation for picture loading
. Dontanimate ()//Set the picture to load directly, do not display the animation . Crossfade ()//settings load picture for fade in
"To set how the image is scaled
. Centercrop () . Fitcenter ()
Note:
. Centercrop () to fit the picture to the size of the view
. Fitcenter () Trim zoom, so that the size of the picture is less than the size of the view, it is possible to account for the size of the view
"Sets the cache for the picture
. Skipmemorycache (True)//Skip Memory Cache
. diskcachestrategy( diskcachestrategy. NONE ) //Skip HDD cache
DiskCacheStrategy.NONEDon't cache anything.
DiskCacheStrategy.SOURCEJust cache the original full-resolution image
DiskCacheStrategy.RESULTOnly the final image is cached, that is, after the resolution is lowered (or converted)
DiskCacheStrategy.ALLCache all versions of images ( default behavior )
"Sets the priority for picture loading
. Priority (Priority.high) Priority.LOWPriority.NORMALPriority.HIGHPriority.IMMEDIATE
"Loading GIF animations
. Asgif ()//Determine if the loaded URL resource is a GIF-formatted resource
"Show pictures
. into (ImageView);
A preliminary study on Android Glide picture loading frame