1.) Add a reference Add configuration in
compile ':glide:3.7.0'
2.) Set the binding life cycle
We can use the method provided by Glide to bind more efficiently, so that the life cycle of the request to load images can be dynamically managed.
(Context context);// Bind Context (Activity activity);// Bind Activity (FragmentActivity activity);// Bind FragmentActivity (Fragment fragment);// BindFragment
3.) Simple loading of image instances
(this).load(imageUrl).into(imageView);
4.) Setting up pictures that are loading and failing to load
There are polymorphic implementations in the API for placeholder() and error() functions. You can be familiar with it specifically when using it.
(this).load(imageUrl).placeholder(.ic_launcher).error(.ic_launcher).into(imageView);
5.) Set skip memory cache
(this).load(imageUrl).skipMemoryCache(true).into(imageView);
6.) Set download priority
(this).load(imageUrl).priority().into(imageView);
7.) Set up a cache policy
(this).load(imageUrl).diskCacheStrategy().into(imageView); // Strategy commentary: // all: cache source resources and converted resources // none: No disk cache is available // source: cache source resources // result:Cache converted resources
8.) Set loading animation
//api also provides several commonly used animations: such as crossFade()(this).load(imageUrl).animate(.item_alpha_in).into(imageView);
9.) Set thumbnail support
// This will load the thumbnail first and then load the full picture(this).load(imageUrl).thumbnail(0.1f).into(imageView);
10.) Set the loading size
(this).load(imageUrl).override(800, 800).into(imageView);
11.) Set up dynamic conversion
(this).load(imageUrl).centerCrop().into(imageView); // The api provides functions such as centerCrop(), fitCenter(), etc., which can also be customized through custom Transformation // Customize Transformation specific use(this).load(imageUrl).transform(new GlideRoundTransform(this)).into(imageView);
12.) Set the content to be loaded
// There are many functions in the project that need to download the pictures first and then do some synthesis functions, such as the graphic and text mixing in the project ///// How to achieve the goal (this).load(imageUrl).centerCrop().into(new SimpleTarget<GlideDrawable>() { @Override public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) { (resource); } });
13.) Set up the listening request interface, set the use of listening. It can be used to monitor the source of errors in the request, as well as the source of the image. Is it memory or disk
(this).load(imageUrl).listener(new RequestListener<String, GlideDrawable>() { @Override public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) { return false; } @Override public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) { //(resource); return false; } }).into(imageView);
14.) Set dynamic GIF loading method
(this).load(imageUrl).asBitmap().into(imageView);//Show gif static image (this).load(imageUrl).asGif().into(imageView);//showgifDynamic pictures
15.) Dynamic cleanup of cache
(this).clearDiskCache();//Cleaning the disk cache requires execution in the child thread (this).clearMemory();//Clean the memory cache Can beUIProgress in the main thread
The above is all the content of this article. I hope that the content of this article will help you study or work. I also hope to support me more!