使用毕加索将图像大小调整为全宽和固定高度 [英] Resize image to full width and fixed height with Picasso

查看:19
本文介绍了使用毕加索将图像大小调整为全宽和固定高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个垂直线性布局,其中一项是使用毕加索加载的 ImageView.我需要将图像的宽度增加到整个设备宽度,并显示图像的中心部分,并以固定高度(150dp)裁剪.我目前有以下代码:

I have a vertical LinearLayout where one of the items is an ImageView loaded using Picasso. I need to rise the image's width to the full device width, and to display the center part of the image cropped by a fixed height (150dp). I currently have the following code:

Picasso.with(getActivity()) 
    .load(imageUrl) 
    .placeholder(R.drawable.placeholder) 
    .error(R.drawable.error) 
    .resize(screenWidth, imageHeight)
    .centerInside() 
    .into(imageView);

我应该在 screenWidthimageHeight (=150dp) 中输入哪些值?

Which values should I put into screenWidth and imageHeight (=150dp)?

推荐答案

你在找:

.fit().centerCrop()

这些是什么意思:

  • fit - 等到 ImageView 被测量并调整图像大小以完全匹配它的大小.
  • centerCrop - 按照纵横比缩放图像,直到它填满大小.裁剪上下或左右,使其与尺寸完全匹配.
  • fit - wait until the ImageView has been measured and resize the image to exactly match its size.
  • centerCrop - scale the image honoring the aspect ratio until it fills the size. Crop either the top and bottom or left and right so it matches the size exactly.

这篇关于使用毕加索将图像大小调整为全宽和固定高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆