Simple Introduction
At the Google Developer Forum in Thailand, Google introduced a picture named Glide to the library, the author is Bumptech. The library is widely used in Google's open source projects, including the official app announced at the 2014 Google I/O conference.
Characteristics
(1) Easy to use
(2) high degree of adaptability and high adaptive degree
(3) Support Common image format: Jpg png gif WEBP
(4) Support a variety of data sources: network, local, resources, Assets, etc.
(5) Efficient cache policy: support memory and Disk image cache, the default Bitmap format with rgb_565, the use of at least half of RAM.
(6) Life cycle Integration: Proactively manage requests based on activity/fragment life cycle
(7) Efficient processing of Bitmap: Use Bitmap Pool to make Bitmap reuse, active call recycle recovery need to recover Bitmap, reduce system recovery pressure.
Feature API Description: 1) Simple to use:
Glide .with(this) .load("http://xxx.com/source/a.png") .into(imageView);
2) use of Glide.with ()
(1) with (context context). With the application context, Glide requests are not controlled by the activity/fragment lifecycle.
(2) with (activity activity). Use activity as the context. Glide requests are subject to Activity lifecycle control.
(3) with (fragmentactivity activity). Glide requests are subject to fragmentactivity lifecycle control.
(4) with (Android.app.Fragment Fragment). Glide requests are subject to fragment lifecycle control.
(5) with (Android.support.v4.app.Fragment Fragment). Glide requests are subject to Fragment lifecycle control.
3) Use of load ()
Glide is basically able to load whatever media resources it can get
- SD Card resources:
Load ("file://" + environment.getexternalstoragedirectory (). GetPath () + "/test.jpg")
- Assets Resources:
Load ("File:///android_asset/3.gif")
- Raw resources:
Load ("Android.resource://com.frank.glide/raw/raw_1") or Load ("android.resource://com.frank.glide/raw/" +R.raw.raw_ 1)
- Drawable Resources:
Load ("Android.resource://com.veyron.glide/drawable/news") or Load ("android.resource://comveyron.glide/drawable/" + R.drawable.news)
- ContentProvider Resources:
Load ("content://media/external/images/media/139469")
- HTTP resources:
Load ("Http://img.my.csdn.NET/uploads/201508/05/1438760757_3588.jpg")
- HTTPS Resources:
Load ("HTTPS://IMG.ALICDN.COM/TPS/TB1UYHOMPXXXXCLXVXXXXXXXXXX-476-538.JPG_240X5000Q50.JPG_.WEBP")
In addition, load is not limited to string types:
load(Uri uri),loadfile),load(Integer resourceId),load(URL url)。load(byte[] model),load
4) Important functions
(1) Disable the memory cache:. Skipmemorycache (true)(2) Clear the memory cache://must be called in the UI threadGlide.get (context). Clearmemory (); (3Disable the disk cache:. Diskcachestrategy (Diskcachestrategy.none) (4) to clear the disk cache://must be called in a background thread. Suggested at the same time clearmemory ()Glide.get (ApplicationContext). Cleardiskcache (); (5) Gets the cache size:NewGetdiskcachesizetask (TextView). Execute (NewFile (Getcachedir (), DiskCache.Factory.DEFAULT_DISK_CACHE_DIR)), class Getdiskcachesizetask extends asynctask< File, Long, long> {Private FinalTextView Resultview; Public Getdiskcachesizetask(TextView Resultview) { This. Resultview = Resultview;}@Overrideprotected void OnPreExecute() {Resultview.settext ("Calculating ...");}@Overrideprotected void onprogressupdate(Long ... values) {/* OnPostExecute (values[values.length-1]); */}@OverrideprotectedLongDoinbackground(File ... dirs) {Try{LongTotalSize =0; for(File dir:dirs) {publishprogress (totalsize); TotalSize + = Calculatesize (dir); }returnTotalSize; }Catch(RuntimeException ex) {FinalString message = String.Format ("Cannot get size of%s:%s", Arrays.tostring (dirs), ex);NewHandler (Looper.getmainlooper ()). Post (NewRunnable () {@Override Public void Run() {Resultview.settext ("Error"); Toast.maketext (Resultview.getcontext (), message, Toast.length_long). Show (); } }); }return 0L;}@Overrideprotected void OnPostExecute(Long size) {String Sizetext = android.text.format.Formatter.formatFileSize (Resultview.getcontext (), size); Resultview.settext (Sizetext);}Private Static Long calculatesize(File dir) {if(dir = =NULL)return 0;if(!dir.isdirectory ())returnDir.length ();Longresult =0; File[] Children = dir.listfiles ();if(Children! =NULL) for(File child:children) result + = Calculatesize (child);returnResult;}} (6Specifies the priority load order of the resources://Priority loadingGlide. With (context), load (Heroimageurl). Priority (Priority.high). to (Imageviewhero);//Post loadingGlide. With (context), load (Itemimageurl). Priority (Priority.low). into (Imageviewitem); (7The thumbnail is displayed first, and then the original image is displayed://Use 1/10 of the original image as a thumbnailGlide. With ( This). Load ("Http://inthecheesefactory.com/uploads/source/nestedfragment/fragments.png"). Thumbnail (0.1f). into (IV_0);//Use other images as thumbnailsDrawablerequestbuilder<integer> thumbnailrequest = Glide. With ( This). Load (r.drawable.news); Glide.with ( This). Load ("Http://inthecheesefactory.com/uploads/source/nestedfragment/fragments.png"). Thumbnail (thumbnailrequest). into (IV_0); (8) to crop, blur, filter, and so on: Detailed view of the demo source code
5) Some API introduction:
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbgvhzl8xmza=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "alt=" here to write a picture descriptive narrative "title=" ">
Add:
CenterCrop()fitCenter() 也是裁剪技术,即缩放图像让图像都測量出来等于或小于 ImageView 的边界范围。该图像将会全然显示,但可能不会填满整个 ImageView。
Steps to use:
1) Add dependency in Build.gradle:
‘com.github.bumptech.glide:glide:3.7.0‘
2) Assuming that your project does not have a support-v4 library, you also need to join SUPPORT-V4 dependencies:
‘com.android.support:support-v4:23.3.0‘
3) Assume that the transformation is used. Ability to add a self-defined transform library
Join dependencies:
‘jp.wasabeef:glide-transformations:2.0.1‘ Iftouse‘jp.co.cyberagent.android.gpuimage:gpuimage-library:1.3.0‘
DemoExampleforglide something
Please follow my public number.
Not only original technical articles, but many others are a summary of the thinking of life
"Android Advanced" image loading frame Glide