By using Glide I set placeholder on image view but the problem is, it is shown on whole image view, I want my placeholder size to be 50dp/50dp but image should be setScale(fitXY)
.
I solved the problem in glide listener
, I am resizing image view on runtime, if it get image from server then imageview width,height(x,y) if not then (x,y).
Glide.with(context)
.load(news.getUrlToImage())
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(131, 131);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
holder.NewsImage.setLayoutParams(layoutParams);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(495, 360);
holder.NewsImage.setLayoutParams(layoutParams);
holder.NewsImage.setScaleType(ImageView.ScaleType.FIT_XY);
return false;
}
}).apply(new RequestOptions().placeholder(R.drawable.place_holder).dontAnimate())
.into(holder.NewsImage);
But the problem is, if there is no image from server it show placeholder of size(50,50) fine and when it has image and glide take some mili seconds to upload image, in that time it shows placeholder on whole image view.
HELP ME