How can I do this using Glide? I want to cache
image to use it another time also. Thanks in advance.
You can load an image in a RelativeLayout like this. I'm just showing you the hard part which is setting an image to the background.
For Glide version before 4.X
Glide.with(this).load(imageViewPath).asBitmap().into(new SimpleTarget(relLayoutWidth, relLayoutHeight) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation super Bitmap> glideAnimation) {
Drawable drawable = new BitmapDrawable(context.getResources(), resource);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
yourRelativeLayout.setBackground(drawable);
}
}
});
For caching, refer to this page: Caching and Cache Invalidation.
Update for Glide v4 onward:
GlideApp.with(this).load(R.drawable.backgroundimage).into(new SimpleTarget() {
@Override
public void onResourceReady(Drawable resource, Transition super Drawable> transition) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
yourRelativeLayout.setBackground(resource);
}
}
});