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 theImageViewhas 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.
这篇关于使用毕加索将图像大小调整为全宽和固定高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用毕加索将图像大小调整为全宽和固定高度
基础教程推荐
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- Maven:无效的目标版本:10 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- JPA惰性列表上的流 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
