Android image smooth scrolling component Glide

Android image smooth scrolling component Glide

Glide is an Android-based image loading and caching component that can read, decode, and display images and videos on Android devices with the highest performance. Glide can cache remote images, videos, animated images, etc. locally on the device to improve the user's smooth browsing experience.

The core function of Glide is to improve the performance of scrolling image lists, and Glide can also meet the performance requirements of reading, resizing and displaying remote images.

How to use Glide

The simplest example code is as follows:

  1. // For a simple view:  
  2. @Override  
  3. public   void onCreate(Bundle savedInstanceState) {
  4. ...
  5.  
  6. ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
  7.  
  8. Glide.with( this ).load( "http://goo.gl/h8qOq7" ).into(imageView);
  9. }
  10.  
  11. // For a list:  
  12. @Override  
  13. public View getView( int position, View recycled, ViewGroup container) {
  14. final ImageView myImageView;
  15. if (recycled == null ) {
  16. myImageView = (ImageView) inflater.inflate(R.layout.my_image_view,
  17. container, false );
  18. } else {
  19. myImageView = (ImageView) recycled;
  20. }
  21.  
  22. String url = myUrls.get(position);
  23.  
  24. Glide.with(myFragment)
  25. .load(url)
  26. .centerCrop()
  27. .placeholder(R.drawable.loading_spinner)
  28. .crossFade()
  29. .into(myImageView);
  30.  
  31. return myImageView;
  32. }

Applying Volley communication framework on Glide

Volley is an option for Glide that supports http/https to read images.

Using Gradle:

  1. dependencies {
  2. compile 'com.github.bumptech.glide:volley-integration:1.0.+'  
  3. compile 'com.mcxiaoke.volley:library:1.0.+'  
  4. }

Or using Maven:

  1. < dependency >   
  2. <groupId> com.github.bumptech.glide </groupId>   
  3. <artifactId> volley - integration </artifactId>   
  4. <version> 1.0.1 </version>   
  5. < type > jar </ type >   
  6. </ dependency >   
  7. < dependency >   
  8. <groupId> com.mcxiaoke.volley </groupId>   
  9. <artifactId> library </artifactId>   
  10. <version> 1.0.5 </version>   
  11. < type > aar </ type >   
  12. </ dependency >   

Then register the Volley add-on in your Activity or Application:

  1. public   void onCreate() {
  2. Glide.get( this ).register(GlideUrl. class , InputStream. class ,
  3. new VolleyUrlLoader.Factory(yourRequestQueue));
  4. ...
  5. }

This way all requests will go through Volley.

Applying OkHttp communication framework in Glide

In addition to Volley, Glide can also use the OkHttp communication framework, which also supports http/https to read images.

Using Gradle:

  1. dependencies {
  2. compile 'com.github.bumptech.glide:okhttp-integration:1.0.+'  
  3. compile 'com.squareup.okhttp:okhttp:2.0.+'  
  4. }

Or using Maven:

  1. <dependency>
  2. <groupId>com.github.bumptech.glide</groupId>
  3. <artifactId>okhttp-integration</artifactId>
  4. <version> 1.0 . 1 </version>
  5. <type>jar</type>
  6. </dependency>
  7. <dependency>
  8. <groupId>com.squareup.okhttp</groupId>
  9. <artifactId>okhttp</artifactId>
  10. <version> 2.0 . 0 </version>
  11. <type>jar</type>
  12. </dependency>
  13.  
  14. Then register the OkHttp add-on in your Activity or Application:
  15.  
  16. public   void onCreate() {
  17. Glide.get( this ).register(GlideUrl. class , InputStream. class ,
  18. new OkHttpUrlLoader.Factory(yourOkHttpClient));
  19. ...
  20. }

Summarize

If your Android application involves remote image processing, the Glide component can help you optimize your application in terms of images and videos.

Software Home

Software Documentation

Software Download

Link to this article: http://www.codeceo.com/article/android-glide.html

Author of this article: Xiaofeng

<<:  Google may release Android 5.0, Nexus 6 and Nexus 9 today

>>:  iPhone6 ​​resolution and adaptation

Recommend

APP promotion: A brief discussion on the cold start of Internet products!

No matter how cool the concept of a product is or...

WeChat 8.0.6 iOS version is officially launched with these 6 major changes

In actual testing, although there are no major fu...

ENISA: 2023 AI and Standardized Cybersecurity Report

ENISA has published the "Cybersecurity Repor...

Cooling down! Blizzard! Cold front is coming again

The cold air is coming again! November 19-22 Rain...

What I mean is, is it necessary to remove armpit hair?

Review expert: Zhang Yuhong Zhengzhou Central Hos...

How do community apps stimulate users to produce high-quality content?

The product chain of a community product is: &quo...

If eaten by mistake, it will cause poisoning! Don't let it be on your table

Spring is rainy and humid Various wild mushrooms ...

React mobile enterprise data project practice

Course Description This project starts with getti...

A comprehensive collection of Xiaohongshu operation tools!

If you want to do your work well, you must first ...