Home Tutorials Training Consulting Products Books Company Donate Contact us









NOW Hiring

Quick links

Share

This tutorial describes how to download efficiently images using Google Glide.

1. Google Glide for image processing

Every application needs to download and manage images.

Google Glide makes this easy.

To use Glide add the following dependency to your app/build.gradle file.

dependencies {
    compile 'com.github.bumptech.glide:glide:3.8.0'
    compile 'com.android.support:support-v4:25.3.1'
    // more stuff
}

The usage is simple.

// simple usage
Glide.with(myListFragment)
    .load("url").into(imageView)

// with placeholder
    Glide.with(myListFragment)
    .load("url").placeholder(R.drawable.loading_spinner).into(imageView)

2. Exercise - Using Glide to download images into your RecyclerView

Use Glide to download images into your RecyclerView adapter. As a first step add the Glide dependencies to your Gradle build file.

dependencies {
    compile 'com.github.bumptech.glide:glide:3.8.0'
    compile 'com.android.support:support-v4:25.3.1'
    // more stuff
}

The Internet provides free example picture services for testing, for example:

Adjust your adapter implementation in your Recyclerview.

   @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        final RssItem rssItem = rssItems.get(position);
        holder.txtHeader.setText(rssItem.getTitle());
        holder.txtFooter.setText(rssItem.getLink());
        holder.mainLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                myListFragment.updateDetail(rssItem.getLink());
            }
        });
        // to download some random data
        Random r = new Random();
        int i = r.nextInt(10);
        Glide.with(myListFragment).load("http://lorempixel.com/400/200/sports/"+i+"/").
                into(holder.imageView);
    }
Glide output result in RecyclerView

3. About this website

4.2. vogella GmbH training and consulting support

TRAINING SERVICE & SUPPORT

The vogella company provides comprehensive training and education services from experts in the areas of Eclipse RCP, Android, Git, Java, Gradle and Spring. We offer both public and inhouse training. Whichever course you decide to take, you are guaranteed to experience what many before you refer to as “The best IT class I have ever attended”.

The vogella company offers expert consulting services, development support and coaching. Our customers range from Fortune 100 corporations to individual developers.

Copyright © 2012-2017 vogella GmbH. Free use of the software examples is granted under the terms of the EPL License. This tutorial is published under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license.

See Licence.