2
votes

I'm trying to load an image using 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;

It's showing nothing.

However if I change that last line to Picasso:

    Picasso.with(context).load(part.getContent()).into(imageView);

Image loads at full size just as I was expecting.

Also. If I use Glide with a placeholder:

    Glide.with(context).load(part.getContent()).placeholder(R.mipmap.def_avatar).into(imageView);

It loads the image but in a very small size (the size of R.mipmap.def_avatar)

I want to be able to load the real size image without having to specify placeholders (its a dynamic view and its supposed to show a lot of different images with different sizes and so)

I want to use Glide instead of Picasso because I want support for animated gifs.

2
I forgot to say that the image is loading from the internet. It's not a local image. - Enuff
may be because of you adding view dynamically. try to set fix height and width of ImageView - Kishore Jethava
Yep, looks like adding adding a fixed size shows the image. The thing is I can't know beforehand how big the image is going to be. - Enuff
You should use ImageView from xml and second thing contents is RelaiveLayout or What? - Kishore Jethava
I can't do if from xml, the parent (contents) is a LinearLayout and I have no idea how many ImageViews or TextViews it will contain or the size of that images - Enuff

2 Answers

6
votes

Looks like adding override does the trick. Image is now loading as expected.

Glide.with(context).load(part.getContent()).override(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).into(imageView);
1
votes

I just solved this issue for myself, having the following attributes set on my ImageView in the XML did the trick for me:

<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>

For reference here is also my Android code:

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

}