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 can copy impress your users? Let’s add one more sentence: And then what?

When you go shopping, have you ever felt that som...

Tide, tide, tide! Say no to getting wet during the rainy season

"When it rains at the beginning of the plum ...

Popular science drama "100,000 Whys: Winter Olympics Special"

Introduction to the resources of the popular scie...

Analysis of the competition between TikTok and Tencent Weishi

Short videos have become an important part of peo...

The rise of HTML5 - not just an inspirational drama, but also a palace drama

[[141431]] HTML5 is popular. In the past two year...

Which version of iPhone 6S is the best?

iPhone 6s has been on the market for more than two...

The United States announced: visa sanctions on some Huawei employees

According to Global Times reports from multiple f...