57

Today I'm trying to use Glide image loader in my android application while using this I had facing method not resolving problem.

Glide
     .with(this)
     .load(R.drawable.image_default_profile_picture)
     .into(mUserImage);

This code working pretty fine. But when I'm trying this

Glide
     .with(this)
     .load(R.drawable.image_default_profile_picture)
     .placeholder(R.mipmap.ic_launcher)
     .fitCenter()
     .into(mUserImage);

Then this saying cannot resolve method fitCenter(), placeholder. What I am missing?

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
user3528954
  • 867
  • 3
  • 10
  • 17

7 Answers7

113

Seems like updated library has any issue. Add .apply(new RequestOptions() to continue with latest version.

CODE

Glide
 .with(this)
 .load(R.drawable.image_default_profile_picture)
 .apply(new RequestOptions()
 .placeholder(R.mipmap.ic_launcher)
 .fitCenter())
 .into(mUserImage);
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
PEHLAJ
  • 9,980
  • 9
  • 41
  • 53
  • That worked for me, thanks! One side note, you can leave the 'annotationProcessor` as is (4.0.0-RC0). – lidkxx May 26 '17 at 15:29
  • 1
    Ive already done this.But cannot resolve issues.ver `3.5.2` won't let me use asGIf() method. – Sachin Bahukhandi Jun 18 '17 at 15:29
  • this is not the solution to downgrade version, please go with @James Jordan Taylor's answer. – Bhavesh Rangani Jan 23 '18 at 05:57
  • Sameer Bhat tried to edit the post with this comment: "you missed a closing round bracket, thanks btw" I'm not sure if they proposed a correct change, but please review your syntax – YakovL Jan 26 '18 at 14:18
  • `Glide.with(context*).using(FirebaseImageLoader()).load(storageReference).into(holder.image)`. `using` method not found. Can you help on this. – Kalanidhi Aug 16 '18 at 08:30
47

You can still use .placeholder() with the latest version of Glide, you just have to add it as an applied RequestOption in the method chain, i.e.

Glide.with(this)
     .load(floorplanUrl)
     .apply(new RequestOptions()
           .placeholder(R.drawable.floorplan_unavailable))
     .into(floorplanImageView);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
James Jordan Taylor
  • 1,560
  • 3
  • 24
  • 38
  • this should be accepted answer instead of giving an answer to downgrade the glide version. – Bhavesh Rangani Jan 23 '18 at 06:01
  • Thank you, this was very helpful! I just upgraded old code and some references threw an error. I see this is needed now when using Default Glide rather than the Customizable Fluid Interface in which case we need to reference GlideApp instead. I got the Customizable Image Loading on Android by Peitek and Pohls book for more explanations and examples. – Lucy Jan 27 '18 at 13:53
38

If you use Glide package dependences compile 'com.github.bumptech.glide:glide:3.7.0' than use below code

Glide
    .with(your_context)
    .load(image_url)
    .centerCrop()
    .placeholder(R.drawable.image_loading)
    .error(R.drawable.image_error)
    .into(imageView);

Note: As in doc Round Pictures: CircleImageView/CircularImageView/RoundedImageView are known to have issues with TransitionDrawable (.crossFade() with .thumbnail() or .placeholder()) and animated GIFs, use a BitmapTransformation (.circleCrop() will be available in v4) or .dontAnimate() to fix the issue.

Latest update version compile 'com.github.bumptech.glide:glide:4.1.1' or above than use below code

Glide.with(your_context)
     .load(url)
     .apply(new RequestOptions()
                .placeholder(R.mipmap.ic_loading_image)
                .centerCrop()
                .dontAnimate()
                .dontTransform())
                .into(imageView);

If you want to load GIF File in to Glide with using compile 'com.github.bumptech.glide:glide:3.7.0' than use .asGif() method after .load()

Glide
    .with(your_context)
    .load(image_url)
    .asGif()
    .into(imageView);

If you use compile 'com.github.bumptech.glide:glide:4.1.1' or higher(latest) dependences than,

Glide
    .with(your_context)
    .asGif()
    .load(image_url)
    .into(imageView);

Note: If you are useing glide:glide:4.1.1 or higher version than not necessary to use .asGif() method to load GIF file it will load GIF File automatically

See Latest version of glide, Bug fixes, Features

ND1010_
  • 3,743
  • 24
  • 41
16

For using fitCenter() and other scale type changes with the Glide version starting from v4.0, you need include special class in your app.

import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

@GlideModule
public class MyAppGlideModule extends AppGlideModule {
}

After that rebuild the project, and you can start using Glide on that manner

GlideApp.with(imageView)
    .load("...")
    .fitCenter()
    .into(imageView);

Documentation

Airon Tark
  • 8,900
  • 4
  • 23
  • 19
4

Glide version: 4.8.0

Glide.with(this)
        .load("https://media.giphy.com/media/98uBZTzlXMhkk/giphy.gif")
        .apply(new RequestOptions()
                .placeholder(R.drawable.placeholder)
                .error(R.drawable.error)
                .centerCrop()
                .fitCenter())
        .into(imageView);
duyuanchao
  • 3,863
  • 1
  • 25
  • 16
1

If you still want to use the newest library 'com.github.bumptech.glide:glide:4.0.0-RC1', The official Github page suggests the following:

Round Pictures: CircleImageView/CircularImageView/RoundedImageView are known to have issues with TransitionDrawable (.crossFade() with .thumbnail() or .placeholder()) and animated GIFs, use a BitmapTransformation (.circleCrop() will be available in v4) or .dontAnimate() to fix the issue.

Otherwise use the following library version:

compile 'com.github.bumptech.glide:glide:3.7.0'
Darush
  • 11,403
  • 9
  • 62
  • 60
-2

compile this library:-

compile 'com.github.bumptech.glide:glide:3.7.0'
V.N.G
  • 13
  • 4