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

Back to school season, these safety tips should be kept in mind! - Traffic

The new semester is about to begin. Children on t...

Changan Dashiren 2020 Special Class Video Course

Introduction to Changan Dashiren's 2020 small...

How to plan a large-scale promotional event?

What are the big promotions? It generally refers ...

What? You said the secret to delicious soda isn’t the bubbles?

Opening a bottle of iced soda and drinking it in ...

Ma Fang's 12 Principles of the Workplace

Ma Fang's 12 Lectures on "12 Principles ...

Are you sure the name Youyouguan is not meant to be cute?

What would you do if you found out that your room...

Analyst: iPhone will need a big price cut or redesign next year

Earlier this year, Wedbush Securities analyst Dan...

Li Niuniu-Live Selling Practical Course

Li Niuniu - Live Streaming Sales Course Resource I...

Business logic splitting based on micro frontend

1. What is a micro frontend? Micro frontends are ...

98sjw Catering Franchise Website Analysis Report

1. Keyword analysis The keywords of 98sjw caterin...

Product promotion from 0 to 1: How to acquire seed users?

Today we will introduce in detail how to write co...

Hot 2022 Chengdu Tea Tasting with its own studio

Reservation arrangements for Chengdu Tea Tasting ...