Skip to content
Advertisement

How to load image in Picasso correctly

**Hi, i’m trying load images from url like this: link

As you can see, the images have different sizes. For example, the first image is 1920×1280 in size. The second image is 720×11523 in size and the last image is 720×5420 in size.

But, this in my application looks like this:

The first image is cut off The rest of the images are not centered

JavaScript

In this link

As you can see, the images have different sizes. For example, the first image is 1702×1080 in size. The second image is 1170×1618 in size and the last image is 986×1238 in size.

In my application looks like this: same problems, images are cropped, not centered and do not occupy the entire width of the screen

This is my adapter layout:

JavaScript

My adapter class:

JavaScript

My Activity layout:

JavaScript

My activity class:

JavaScript

How can I solve the mentioned problems?

Advertisement

Answer

Try using Picasso’s fit() function combined with a centerCrop() or centerInside(). You can read about these functions here.

Try changing onBindViewHolder to the following:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement