Android component Glide to achieve smooth scrolling effect of picture _android

Source: Internet
Author: User

Glide is an Android based image loading and image caching component that can read, decode, and display pictures and videos on Android devices with maximum performance. Glide can be remote pictures, video, animation pictures, such as slow presence of equipment local, easy to improve the user to browse the image of the fluent experience.

The core function of glide is to improve the performance of the scrolling picture list, and glide can also meet the performance requirements for reading, resizing, and displaying remote images.

How to use Glide

The simplest example code is as follows:

For a simple view:
@Override the 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 Imagev Iew 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;
}

Application of volley communication framework on glide

Volley is an optional glide that can support Http/https to read pictures.

With 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>

Then register the volley add-in in the activity or application:

public void OnCreate () {
 glide.get (this). Register (Glideurl.class, Inputstream.class,
    new Volleyurlloader.factory (Yourrequestqueue));
 ...
}

So all the requests will be passed through the volley.

Application of okhttp communication framework in Glide

In addition to volley,glide you can use the Okhttp communication framework, Okhttp also supports Http/https to read pictures.

With 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-in in the activity or application:

public void OnCreate () {
 glide.get (this). Register (Glideurl.class, Inputstream.class,
    new Okhttpurlloader.factory (yourokhttpclient));
 ...
}

Summarize

If your Android application involves remote image processing, the glide component can help you optimize your application in image video.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.