scaling image size in Picasso

不打扰是莪最后的温柔 提交于 2019-12-06 05:52:32

问题


I want to download an image from a URL and display it in a View in my fragment. I am using Picasso to do this but I want the image to display in it's original aspect ratio but scaled to be a reasonable size - ie 75% of the screen width. I want to support both landscape and portrait photos. So the thinking is something like this.

If the screen width is 200 and the image is landscape 5x4 aspect, then the image should be displayed to 75% width - ie 150 and 120 height (keeping proportions)

If the screen width is 200 and the image is portrait 4x5 aspect, then the image should be display to 75% screen width as the HEIGHT dimension - ie 150 height and 120 width

How can I do this using Picasso?


回答1:


Breaking the first part down in to two sections:

I want the image to display in it's original aspect ratio

To do this you can call .fit().centerInside() on the Picasso request

scaled to be a reasonable size - ie 75% of the screen width

The easiest way to do this would be to specify this in your layout, so set an ImageView to be this width. Then when Picasso loads the image into this ImageView it will automatically scale it to fit (but keeping the aspect ratio as specified above).



来源:https://stackoverflow.com/questions/24807479/scaling-image-size-in-picasso

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!