Android image smooth scrolling component Glide

Source: Internet
Author: User

Android image smooth scrolling component Glide

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

The core function of Glide is to improve the performance of the Scrolling Image list, and Glide can meet the performance requirements for reading, changing the size and display of remote images.

Glide usage

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. // For a list: 
  11. @Override 
  12. public View getView(int position, View recycled, ViewGroup container) { 
  13.     final ImageView myImageView; 
  14.     if (recycled == null) { 
  15.         myImageView = (ImageView) inflater.inflate(R.layout.my_image_view, 
  16.                 container, false); 
  17.     } else { 
  18.         myImageView = (ImageView) recycled; 
  19.     } 
  20.  
  21.     String url = myUrls.get(position); 
  22.  
  23.     Glide.with(myFragment) 
  24.         .load(url) 
  25.         .centerCrop() 
  26.         .placeholder(R.drawable.loading_spinner) 
  27.         .crossFade() 
  28.         .into(myImageView); 
  29.  
  30.     return myImageView; 
Apply Volley communication framework on Glide

Volley is an option of Glide. It supports http/https to read images.

Use Gradle:

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

Or use 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>  

Register the Volley add-on in Activity or Application:

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

In this way, all requests will pass Volley.

Apply OkHttp communication framework in Glide

In addition to Volley, The OkHttp communication framework can also be used in Glide. OkHttp also supports http/https to read images.

Use Gradle:

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

Or use 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 Activity or Application:
  15.  
  16. Public void onCreate (){
  17. Glide. get (this). register (GlideUrl. class, InputStream. class,
  18. New OkHttpUrlLoader. Factory (yourOkHttpClient ));
  19. ...
  20. }
Summary

If remote image processing is involved in your Android app, the Glide component helps you optimize the app for image and video processing.

Software Homepage

Software documentation

Software Download

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

Author: Xiaofeng

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.