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

Is live streaming the lifeline for brand marketing?

Whether it is the product side or communication w...

Why are older people more vulnerable to online rumors?

Nowadays, we play with our phones every day, and ...

GlobalData: Covid-19 will not slow down 5G deployment

Data analysis company GlobalData said that despit...

WeChat, Alipay, Baidu, Toutiao: The future battle of the "F4" of mini programs

People always overestimate the changes in the nex...

Where will OPPO go if its differentiated advantage is no longer there?

Among domestic mobile phone manufacturers, OPPO i...

WWDC without hardware: Does Apple want to rebuild its ecosystem?

Although Apple did not release any new hardware p...

How to promote short videos? I have summarized these 6 points!

In recent years, with the rise of short videos, m...