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:
- // For a simple view:
- @Override
- public void onCreate(Bundle savedInstanceState) {
- ...
-
- ImageView imageView = (ImageView) findViewById(R.id.my_image_view);
-
- Glide.with(this).load("http://goo.gl/h8qOq7").into(imageView);
- }
-
- // For a list:
- @Override
- public View getView(int position, View recycled, ViewGroup container) {
- final ImageView myImageView;
- if (recycled == null) {
- myImageView = (ImageView) inflater.inflate(R.layout.my_image_view,
- container, false);
- } else {
- myImageView = (ImageView) recycled;
- }
-
- String url = myUrls.get(position);
-
- Glide.with(myFragment)
- .load(url)
- .centerCrop()
- .placeholder(R.drawable.loading_spinner)
- .crossFade()
- .into(myImageView);
-
- return myImageView;
- }
Apply Volley communication framework on Glide
Volley is an option of Glide. It supports http/https to read images.
Use Gradle:
- dependencies {
- compile 'com.github.bumptech.glide:volley-integration:1.0.+'
- compile 'com.mcxiaoke.volley:library:1.0.+'
- }
Or use Maven:
- <dependency>
- <groupId>com.github.bumptech.glide</groupId>
- <artifactId>volley-integration</artifactId>
- <version>1.0.1</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>com.mcxiaoke.volley</groupId>
- <artifactId>library</artifactId>
- <version>1.0.5</version>
- <type>aar</type>
- </dependency>
Register the Volley add-on in Activity or Application:
- public void onCreate() {
- Glide.get(this).register(GlideUrl.class, InputStream.class,
- new VolleyUrlLoader.Factory(yourRequestQueue));
- ...
- }
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:
- dependencies {
- compile 'com.github.bumptech.glide:okhttp-integration:1.0.+'
- compile 'com.squareup.okhttp:okhttp:2.0.+'
- }
Or use Maven:
- <Dependency>
- <GroupId> com. github. bumptech. glide </groupId>
- <ArtifactId> okhttp-integration </artifactId>
- <Version> 1.0.1 </version>
- <Type> jar </type>
- </Dependency>
- <Dependency>
- <GroupId> com. squareup. okhttp </groupId>
- <ArtifactId> okhttp </artifactId>
- <Version> 2.0.0 </version>
- <Type> jar </type>
- </Dependency>
-
- Then register the OkHttp add-on in Activity or Application:
-
- Public void onCreate (){
- Glide. get (this). register (GlideUrl. class, InputStream. class,
- New OkHttpUrlLoader. Factory (yourOkHttpClient ));
- ...
- }
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