In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the usage of Glide in Android Picture loading Library". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the usage of Glide in Android Picture loading Library".
Glide introduction
Glide is a fast and efficient Android image loading library that focuses on smooth scrolling. Glide provides easy-to-use API, high-performance, scalable image decoding pipeline, and automatic resource pool technology. The main goal of Glide is to make the scrolling of any kind of picture list as fast and smooth as possible.
Android SDK requirements
Min Sdk Version-min SDK version API 14 (Ice Cream Sandwich) or higher is required to use Glide.
Compile Sdk Version-Glide must be compiled using API 27 (Oreo MR1) or later SDK.
Support Library Version-Glide uses version 27 of the support library.
Preparation before use
download
Jar
You can download the latest jar package directly from GitHub. You also need a jar package that contains the Android v4 support library.
Gradle
Add the following dependencies to build.gradle
Implementation 'com.github.bumptech.glide:glide:4.12.0'annotationProcessor' com.github.bumptech.glide:compiler:4.12.0'
Maven
If you use Maven, you can also add dependencies on Glide. Again, you still need to add dependencies on the Android support library
Com.github.bumptech.glide glide 4.11.0 aar com.google.android support-v4 r7 com.github.bumptech.glide compiler 4.11.0 true
Set up
Load pictures from the network
Load pictures from local storage
Basic usage Glide.with (fragment) / / pass activity or fragment .load (url) / / local or network address .into (imageView); / / ImageView object
This allows the picture to be loaded into the specified ImageView
Use in ListView and RecyclerView
The code for loading pictures in ListView or RecyclerView is exactly the same as loading in a separate View
@ Overridepublic void onBindViewHolder (ViewHolder holder, int position) {String url = urls.get (position); Glide.with (fragment) .load (url) .into (holder.imageView);} placeholder
Glide has three placeholders: show placeholder Drawable when the request is executing, error Drawable if the request fails, and null if the url of the request is null, then fallback url will be displayed
Glide.with (activity) .load (url) .placeholder (R.drawable.loading) / / Picture displayed when requesting a picture. Error (R.drawable.error) / / Picture displayed when request fails. Fallback (R.drawable.fallback) / / Picture address (url) is empty. Into (imageView) Option RequestOptions requestOptions = new RequestOptions () .placeholder (R.drawable.loading) .error (R.drawable.error); Glide.with (fragment) .load (url) .apply (requestOptions) .into (imageView)
The apply () method can be called multiple times, so RequestOption can be combined. If there are conflicting settings between RequestOptions objects, only the last applied RequestOptions will take effect.
Transition animation
In Glide, Transitions allows you to define how Glide transitions from placeholders to newly loaded images, or from thumbnails to full-size images. Transition works in the context of a single request, not across multiple requests. Therefore, Transitions does not allow you to define animation from one request to another (for example, cross-fade effects)
DrawableCrossFadeFactory factory = new DrawableCrossFadeFactory.Builder (). SetCrossFadeEnabled (true). Build (); GlideApp.with (context) .load (url) .apply (requestOptions) .placeholder (R.color.placeholder) .into (imageView)
In addition to the cross-fade effect, you can also customize
Transformation effect
May not be converted when the url address is png
RequestOptions requestOptions = new RequestOptions () .placeholder (R.drawable.loading) .error (R.drawable.error) Glide.with (MainActivity.this) .load (url) .apply (requestOptions) .transform (new CircleCrop ()) / / fillet picture / / .transform (new RoundedCorners (30)) / / circular picture angle unify / / .transform (new GranularRoundedCorners (30,50,70,80)) / / four corners separately specify the angle / / .transform (new Rotate (90)) / / rotate the angle clockwise .into (imageView)
Fillet transformation effect
Clockwise rotation effect
Use the example
Loading and error are downloaded to the local image in advance and placed in drawable. Url can be the address of a network image.
Public class MainActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); String url = "url of picture"; ImageView imageView = findViewById (R.id.image_view) Glide.with (this) .load (url) .placeholder (R.drawable.loading) .error (R.drawable.error) .into (imageView);}}
Layout file
The permissions are set as follows
The following figure shows how the network address is loaded. If the wrong network address is passed in the left, the error diagram will be displayed; if the network picture address is correct, the correct picture will be put into the ImageView; and when the picture is not loaded, the ImageView will show the loading diagram.
Thank you for reading, the above is the content of "what is the usage of Glide in Android Picture loading Library". After the study of this article, I believe you have a deeper understanding of what the usage of Glide in Android Picture loading Library is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.