
recyclerview 渲染服务端图片不显示的原因
使用 recyclerview 显示服务端图片时,如果图片不显示,可能是因为以下原因:
- imageview 高度设置为 wrap_content
在布局文件中,如果 imageview 的高度设置为 wrap_content,则在图片加载之前,系统无法确定其高度,从而导致无法显示。
AI 舌诊面诊问诊医疗系统 + 诊疗商城系统源码是一套结合 AI 辅助诊断与商品转化的健康类程序,基于浩创云、ThinkPHP(PHP)开发,支持微信服务号与 H5 端,适合做中医舌诊面诊问答、健康建议推送以及配套诊疗商品的运营。
解决方案:
- 指定 imageview 高度(例如,android:layout_height="200dp")
- 使用占位符图片(例如,glide.with(...).load(src).placeholder(r.drawable.placeholder).into(imageview))
动态设置 imageview 高度
如果需要动态设置 imageview 高度,可以使用 glide 的监听器:
Glide.with(this.activity.getBaseContext())
.load(src)
.addListener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
// 根据图片宽高比设置 ImageView 高度
int width = imageView.getWidth();
float aspectRatio = (float) resource.getIntrinsicWidth() / (float) resource.getIntrinsicHeight();
int height = Math.round(width / aspectRatio);
imageView.setLayoutParams(new ViewGroup.LayoutParams(width, height));
return false;
}
})
.into(imageView);














