调整图像大小,以完整的宽度和高度固定毕加索 [英] Resize image to full width and fixed height with Picasso

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

问题描述

我有一个垂直的LinearLayout,其中的项目之一是的ImageView 加载使用毕加索。我需要上升图像的宽度,以完整的设备宽度,并显示由一个固定的高度(150dp)裁剪的图像的中心部分。目前,我有以下code:

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);

我应该把哪些值到屏幕宽度 imageHeight (= 150dp)?

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

推荐答案

您正在寻找:

.fit().centerCrop()

这是什么意思:

What these mean:

  • 配合 - 等到的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天全站免登陆