Glide 不加载没有占位符的图像

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:

    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);
    }

}