简体   繁体   English

Android:带有 GridLayoutManager 的 RecyclerView 中的毕加索图像

[英]Android: Picasso image inside a RecyclerView with GridLayoutManager

I want to define an Android screen that has squared images in 3 columns, using the maximum width as possible.我想定义一个在 3 列中具有平方图像的 Android 屏幕,并尽可能使用最大宽度。 I'm using with a RecyclerView that uses a GridLayoutManager and Picasso for loading images.我正在使用 RecyclerView,它使用 GridLayoutManager 和 Picasso 来加载图像。

The problem问题

I'm not able to make the images as big as possible.我无法使图像尽可能大。 I've tried the following:我尝试了以下方法:

Picasso.with(context).load(factory.getImage(value)).fit().into(holder.button);

With this I get a correct width, but the height is resized (getting a distorted image)有了这个,我得到了正确的宽度,但高度调整了大小(得到扭曲的图像)

Picasso.with(context).load(factory.getImage(value)).centerInside().fit().into(holder.button);

With this I get smaller images than what should be.有了这个,我得到的图像比应该的要小。

How can I achieve this?我怎样才能做到这一点?

Thanks,谢谢,

I also faced this problem with images in columns.我也遇到了列中图像的这个问题。 I wanted them to have the fullest width possible and also fit into let's say 3 or 4 columns.我希望它们具有尽可能大的宽度,并且也适合假设 3 或 4 列。 After many experiments I realized I had forgotten to add:经过多次实验,我意识到我忘记添加:

android:adjustViewBounds="true"

to my ImageView .到我的ImageView This solved my problem.这解决了我的问题。 The images now fit the grid layout perfectly!图像现在完全适合网格布局!

Bitmap img = Picasso.with(this).load("http://").get();
int w = img.getWidth();
int h = img.getHeight();

This will get you orignal height and width of an image, Now may be this would help you in yours context这将为您提供图像的原始高度和宽度,现在这可能会对您的上下文有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM