没有占位符

时间:2017-02-22 17:59:10

标签: android picasso android-glide

我正在尝试使用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动画。

1 个答案:

答案 0 :(得分:1)

我刚刚为自己解决了这个问题,在我的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);
    }

}
相关问题