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

How to sell goods through Douyin live streaming? 70 notes!

This is the information I collect on a daily basi...

Tips for building a user operation membership system!

The systematized process standards were also ment...

4 Tips for Analyzing Peers in SEO!

1. Visit the competitor's website as a visito...

Instagram-style scroll view source code download

Functional classification: Other Supported platfo...

How to become popular on Tik Tok? Tik Tok operation method

Today, Tik Tok has become a popular short video A...

Looking back again, the two years stolen by the epidemic

One minute with the doctor, the postures are cons...

Feng Shui selection and layout of shops (Jiang Wenhe)

Jiang Wenhe's "Shop Feng Shui Selection ...

The right approach to brand marketing in 2021

Different from the keywords of traditional e-comm...