B
B
bshtefunyk72017-02-16 00:12:32
Android
bshtefunyk7, 2017-02-16 00:12:32

RecyclerView + Glide - Problem loading images. How to fix?

Hello, I ran into such a problem:
I am loading pictures of different sizes from the Internet through Glide in RecyclerView. The first 7 elements are displayed normally, all subsequent elements are crooked (not full width). (see screenshots). Maybe someone faced such a problem?
b2a130c7053e470bae86a4f0849374e6.jpg
Imageview code:

<ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="fitStart"
        android:src="@drawable/cohete_flat" />

And here I am loading images (in the adapter's onBindViewHolder method):
Glide.with(holder.itemView.getContext()).load(picture.getImageUrl())
        .crossFade()
        .thumbnail(0.5f)
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .into(holder.imageView);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kuchanov, 2017-02-16
@kuchanov

You asked
And it is displayed as such. If you need to fill the width of the container, then try adding fitCenter or centerCrop in the Glide builder. That is, for example:

Glide.with(holder.itemView.getContext()).load(picture.getImageUrl())
        .crossFade()
        .thumbnail(0.5f)
        .centerCrop()
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .into(holder.imageView);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question