[英]Glide not loading image without placeholder
我正在尝试使用Glide加载图像:
case "image":
Log.d("TRecyViewAdapter", "Got Image");
ImageView imageView = new ImageView(context);
imageView.setLayoutParams(new GridLayoutManager.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.MATCH_PARENT
));
contents.addView(imageView);
Glide.with(context).load(part.getContent()).into(imageView);
break;
什么也没显示。
但是,如果我将最后一行更改为毕加索:
Picasso.with(context).load(part.getContent()).into(imageView);
图像加载达到了我的预期。
也。 如果我将Glide与占位符一起使用:
Glide.with(context).load(part.getContent()).placeholder(R.mipmap.def_avatar).into(imageView);
它加载图像,但尺寸很小(R.mipmap.def_avatar的大小)
我希望能够加载实际尺寸的图像而不必指定占位符(它是一个动态视图,它应该显示许多具有不同尺寸的不同图像等等)
我想使用Glide而不是Picasso,因为我希望支持动画gif。
看起来,添加替代功能可以解决问题。 现在正在按预期加载图像。
Glide.with(context).load(part.getContent()).override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).into(imageView);
我只是为我自己解决了这个问题,在XML的ImageView上设置了以下属性可以帮到我:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
</FrameLayout>
供参考的也是我的Android代码:
public class MyCardViewHolder extends CardViewHolder {
public MyCardViewHolder(View inflated) {
super(inflated);
}
public void bind(MyCard card) {
ImageView imageView = ((ImageView) itemView.findViewById(R.id.image));
Glide.with(itemView.getContext())
.load(card.backgroundImageUrl())
.into(imageView);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.