Resize image to full width and fixed height with Picasso(使用毕加索将图像大小调整为全宽和固定高度)
问题描述
我有一个垂直线性布局,其中一项是使用毕加索加载的 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);
我应该在 screenWidth
和 imageHeight
(=150dp) 中输入哪些值?
Which values should I put into screenWidth
and imageHeight
(=150dp)?
推荐答案
你在找:
.fit().centerCrop()
这些是什么意思:
fit
- 等到ImageView
被测量并调整图像大小以完全匹配它的大小.centerCrop
- 按照纵横比缩放图像,直到它填满大小.裁剪上下或左右,使其与尺寸完全匹配.
fit
- wait until theImageView
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.
这篇关于使用毕加索将图像大小调整为全宽和固定高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用毕加索将图像大小调整为全宽和固定高度


- 获取数字的最后一位 2022-01-01
- 转换 ldap 日期 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01