How to load Image into ImageView from Url using Glide v4.0.0RC1
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);
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);
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
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);
}
}