14

I just updated Glide library from v3 to v4 in my application. But Now I am not able to load image from the url. Previously it was working fine with v3.

Here is my Glide code:

Glide.with(context).load(galleryList.get(itemPosition).getImage()).thumbnail(Glide.with(context).load(R.drawable.balls)).apply(options).into(holder.kolamImage);

What is the change in v4? I went through the document but still no help.

sagar suri
  • 4,351
  • 12
  • 59
  • 122

5 Answers5

35

If you are using Glide v4.0.0-RC1 then you need to use RequestOptions to add the placeholder, error image and other option. Here is an working example

RequestOptions options = new RequestOptions()
                    .centerCrop()
                    .placeholder(R.mipmap.ic_launcher_round)
                    .error(R.mipmap.ic_launcher_round);



 Glide.with(this).load(image_url).apply(options).into(imageView);
Jeffrey Rajan
  • 4,391
  • 4
  • 27
  • 37
7
Glide.with(this)
        .load("url here") // image url
        .placeholder(R.drawable.placeholder) // any placeholder to load at start
        .error(R.drawable.imagenotfound)  // any image in case of error
        .override(200, 200) // resizing
        .centerCrop()     
        .into(imageView);  // imageview object
Fattie
  • 27,874
  • 70
  • 431
  • 719
Bharath
  • 277
  • 4
  • 10
4

Below Steps is for load image into imageView from URL :-

create a new Activity like this and load image from given url.

activity_main.xml

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    <ImageView
        android:id="@+id/myOfferImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:scaleType="fitXY" />

</LinearLayout>

MainActivity.java

public class MainActivity extends AppCompatActivity {


    ImageView myOfferImageView;
    String url = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        url = "https://image.url"


        myOfferImageView = findViewById(R.id.myOfferImage);
        Glide.with(this).load(url)
                .placeholder(R.drawable.ic_launcher_background)
                .error(R.drawable.ic_launcher_background)
                .into(myOfferImageView);
    }


}
Pramesh Bhalala
  • 273
  • 1
  • 3
  • 9
3

Glide v4 added a feature of RequestOptions to add placeholder ,error image and to customize image.

RequestOptions options = new RequestOptions()
                    .placeholder(R.drawable.your_placeholder_image)
                    .error(R.drawable.your_error_image);

Glide.with(this).load(image_url).apply(options).into(imageView);
0

Make sure you have quotes around your url, with ivProfileImage being your imageview.

Glide.with(mContext)
    .asBitmap()
    .load("https://i2.wp.com/www.siasat.com/wp-content/uploads/2018/03/Rosamund-Pike.jpeg?fit=600%2C421&ssl=1")
    .into(ivProfileImage);
DragonFire
  • 3,722
  • 2
  • 38
  • 51
  • can i use this in gridview ? https://stackoverflow.com/questions/63490176/how-to-display-firebase-storage-images-in-gridview – Kingg Aug 21 '20 at 04:44