【发布时间】:2019-03-04 02:00:38
【问题描述】:
通过使用 Glide 我在图像视图上设置了 placeholder 但问题是,它显示在整个图像视图上,我希望我的占位符大小为 50dp/50dp 但图片应该是setScale(fitXY)。
我在glide listener 中解决了这个问题,我在运行时调整图像视图的大小,如果它从服务器获取图像然后 imageview width,height(x,y) 如果没有那么 ( 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);
但问题是,如果没有来自服务器的图像,它会显示 size(50,50) 的占位符,并且当它有图像和滑行时需要一些毫秒来上传图像,因为它在整个图像视图上显示占位符的时间。
帮帮我
【问题讨论】:
-
@NileshRathod 是的,这是像素值,与占位符的大小无关
标签: android imageview resize placeholder