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.
这篇关于使用毕加索将图像大小调整为全宽和固定高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用毕加索将图像大小调整为全宽和固定高度
				
        
 
            
        基础教程推荐
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
 - 从 python 访问 JVM 2022-01-01
 - 在 Java 中创建日期的正确方法是什么? 2022-01-01
 - Java Swing计时器未清除 2022-01-01
 - 多个组件的复杂布局 2022-01-01
 - 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
 - 不推荐使用 Api 注释的描述 2022-01-01
 - 验证是否调用了所有 getter 方法 2022-01-01
 - Java 实例变量在两个语句中声明和初始化 2022-01-01
 - 大摇大摆的枚举 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				