-
Notifications
You must be signed in to change notification settings - Fork 0
Displaying Images with the Glide Library
Glide is an Image Loader Library for Android developed by bumptech and is a library that is recommended by Google. It has been used in many Google open source projects including Google I/O 2014 official application.
Guide is incomplete and needs attention
Add to your app/build.gradle
file:
repositories {
mavenCentral() // jcenter() works as well because it pulls from Maven Central
}
dependencies {
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:support-v4:19.1.0'
}
Glide.with(context)
.load("http://pathtoimage.com/graphic.png")
.into(ivImg);
Resizing images with:
Glide.with(context)
.load("http://pathtoimage.com/graphic.png")
.override(300, 200)
.into(ivImg);
Placeholder and error images:
Glide.with(context)
.load("http://pathtoimage.com/graphic.png")
.placeholder(R.drawable.placeholder)
.error(R.drawable.imagenotfound)
.into(ivImg);
Cropping images with:
Glide.with(context)
.load("http://pathtoimage.com/graphic.png")
.centerCrop()
.into(ivImg);
Transforming images with:
Glide.with(context)
.load("http://pathtoimage.com/graphic.png")
.transform(new CircleTransform(context))
.into(ivImg);
You can configure Glide by creating a GlideConfiguration.java
file:
public class GlideConfiguration implements GlideModule {
@Override
public void applyOptions(Context context, GlideBuilder builder) {
// Apply options to the builder here.
// Glide default Bitmap Format is set to RGB_565 since it
// consumed just 50% memory footprint compared to ARGB_8888.
// Increase memory usage for quality with:
builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888);
}
@Override
public void registerComponents(Context context, Glide glide) {
// register ModelLoaders here.
}
}
And then define it as meta-data
inside AndroidManifest.xml
:
- https://github.com/bumptech/glide
- https://inthecheesefactory.com/blog/get-to-know-glide-recommended-by-google/en
- http://www.androidtutorialshub.com/glide-image-loading-library-for-android-tutorial/
- https://futurestud.io/blog/glide-getting-started
- https://github.com/wasabeef/glide-transformations
- http://google-opensource.blogspot.com/2014/09/glide-30-media-management-library-for.html
- http://tutorialwing.com/android-glide-library-tutorial-example/
- http://vardhan-justlikethat.blogspot.com/2014/09/android-image-loading-libraries-picasso.html
- http://www.appance.com/glide-image-loading-and-caching-library-for-android/
- http://www.androidhive.info/2016/04/android-glide-image-library-building-image-gallery-app/
Created by CodePath with much help from the community. Contributed content licensed under cc-wiki with attribution required. You are free to remix and reuse, as long as you attribute and use a similar license.
Finding these guides helpful?
We need help from the broader community to improve these guides, add new topics and keep the topics up-to-date. See our contribution guidelines here and our topic issues list for great ways to help out.
Check these same guides through our standalone viewer for a better browsing experience and an improved search. Follow us on twitter @codepath for access to more useful Android development resources.
Interested in ramping up on Android quickly?
(US Only) If you are an existing engineer with 2+ years of professional experience in software development and are serious about ramping up on Android quickly, be sure to apply for our free evening 8-week Android bootcamp.
We've trained over a thousand engineers from top companies including Apple, Twitter, Airbnb, Uber, and many others leveraging this program. The course is taught by Android experts from the industry and is specifically designed for existing engineers.
Not in the United States? Please fill out our application of interest form and we’ll notify you as classes become available in your area powered by local organizers.