使用毕加索将图像大小调整为全宽和固定高度

我有一个垂直线性布局,其中一项是使用毕加索加载的 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.

相关文章