android – 设置最大宽度以使用Picasso加载图像

weixin_38092995 weixin_38092995 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我的活动中有一个固定的标题,我需要动态加载图像.我需要这个图像来完全填充这个标题,保持宽度和高度的比例. 如果我之前加载图像,我会得到OutOfMemoryException.如果我使用Picasso的fit()方法,该区域将有空格.如果我像StackOverflow中的某些人建议的那样使用Transformation,我也会得到OutOfMemoryException. 我怎么解决这个问题? 标头XML: <FrameLayout android:id="@+id/headerContainer" android:layout_width="match_parent" android:layout_height="140dp" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:background="#ffd5d5d5"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView4" android:layout_gravity="center" android:src="@drawable/background_camera" /> <ViewFlipper android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/viewFlipper" android:layout_gravity="center" > </ViewFlipper> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Adicionar foto do estacionamento" android:id="@+id/textAddPhotos" android:layout_gravity="center" android:textColor="#ff757575" android:padding="10dp" /> <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:id="@+id/addPhotosArea"></RelativeLayout> </FrameLayout> 使用以下代码以编程方式将图像添加到ViewFlipper: final ImageView imageView = new ImageView(SuggestionActivity.this); imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); Picasso.with(SuggestionActivity.this).load(selectedImageUri) .fit().centerInside() .into(imageView); mViewFlipper.addView(imageView); UPDATE 当我加载exif orientation =90º的图像时,我发现Picasso误算了大小. 我正在尝试改变它的来源,但逻辑非常令人困惑. 我认为问题出在BitmapHunter.java文件的这个函数中: static Bitmap transformResult(Request data, Bitmap result, int exifRotation) { int inWidth = result.getWidth(); int inHeight = result.getHeight(); int drawX = 0; int drawY = 0; int drawWidth = inWidth; int drawHeight = inHeight; Matrix matrix = new Matrix(); if (data.needsMatrixTransform()) { int targetWidth = data.targetWidth; int targetHeight = data.targetHeight; float targetRotation = data.rotationDegrees; if (targetRotation != 0) { if (data.hasRotationPivot) { matrix.setRotate(targetRotation, data.rotationPivotX, data.rotationPivotY); } else { matrix.setRotate(targetRotation); } } if (data.centerCrop) { float widthRatio = targetWidth / (float) inWidth; float heightRatio = targetHeight / (float) inHeight; float scale; if (widthRatio > heightRatio) { scale = widthRatio; int newSize = (int) Math.ceil(inHeight * (heightRatio / widthRatio)); drawY = (inHeight - newSize) / 2; drawHeight = newSize; } else { scale = heightRatio; int newSize = (int) Math.ceil(inWidth * (widthRatio / heightRatio)); drawX = (inWidth - newSize) / 2; drawWidth = newSize; } matrix.preScale(scale, scale); } else if (data.centerInside) { float widthRatio = targetWidth / (float) inWidth; float heightRatio = targetHeight / (float) inHeight; float scale = widthRatio < heightRatio ? widthRatio : heightRatio; matrix.preScale(scale, scale); } else if (targetWidth != 0 && targetHeight != 0 // && (targetWidth != inWidth || targetHeight != inHeight)) { // If an explicit target size has been specified and they do not match the results bounds, // pre-scale the existing matrix appropriately. float sx = targetWidth / (float) inWidth; float sy = targetHeight / (float) inHeight; matrix.preScale(sx, sy); } } if (exifRotation != 0) { matrix.preRotate(exifRotation); } Bitmap newResult = Bitmap.createBitmap(result, drawX, drawY, drawWidth, drawHeight, matrix, true); if (newResult != result) { result.recycle(); result = newResult; } return result; }
...全文

相关推荐

AOSP开机动画调测技术点(基于Android13)

开启动画启动规则定义在中disabledoneshotservice: 指明服务的名称为"bootanim",即开机动画服务。: 指定了开机动画的执行文件路径为"/system/bin/bootanimation"。: 表示此服务属于核心服务,并且是与动画相关的服务。: 指定服务运行的用户为"graphics"。: 指定服务运行的组为"graphics audio",表示具有这两个组的权限。disabled: 表示此服务当前处于禁用状态,不会自动启动。oneshot。

Calvin880828

前端开发组件示例源码_f1b6a91d详解

前端开发组件示例源码_f1b6a91d,内容包含源码/脚本与使用说明文档,结构清晰、注释完整,适合学习参考与二次开发,下载解压即可查看。

鱿鱼助手

前端开发基于history.js的HTML5与HTML4浏览器兼容方案:单页应用无刷新历史状态管理技术实现-Gjl4Gf1792158475

内容概要:本文系统介绍了如何利用history.js实现单页应用(SPA)在HTML5c与HTML4浏览器间s草错发的无缝历史状态管理。通过封装原生History API并在不支持的浏览器中自动降级为哈希路由,history.js解决了因浏览器兼容性导致的后退按钮失效、URL混乱等问题。文章详细讲解了其核心机制,包括状态对象管理、自动模式切换(HTML5 pushState vs HTML4 哈希)、状态数据持久化以及针,对Safari、IE等浏\览器的兼容性修复方案,并提供了从入门到实战的完整示例,涵盖初始化、事,件监听、页面加载及性能优化技巧。;Gjl4Gf1792158475 www.gblp.net www.gsctlq.com gezhixq.cn www.greendalian.com wap.gxqnm.com

2601_97196179

前端开发基于history.js的HTML5与HTML4浏览器兼容方案:单页应用无刷新历史状态管理技术实现-5Z6jeSqI1792158476

内容概要:本文系统介绍了如何利用history.js实现单页应用(SPA)在HTML5c与HTML4浏览器间s草错发的无缝历史状态管理。通过封装原生History API并在不支持的浏览器中自动降级为哈希路由,history.js解决了因浏览器兼容性导致的后退按钮失效、URL混乱等问题。文章详细讲解了其核心机制,包括状态对象管理、自动模式切换(HTML5 pushState vs HTML4 哈希)、状态数据持久化以及针,对Safari、IE等浏\览器的兼容性修复方案,并提供了从入门到实战的完整示例,涵盖初始化、事,件监听、页面加载及性能优化技巧。;5Z6jeSqI1792158476 sdhmgggw168.com www.shangliangwangye.com www.sdbing.net migu.blsxex.abxlbz.sc.cn www.safespeed.net.cn

2601_97196179

高校如何通过科技报告服务提升技术转移转化效率?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN
评论 1
收藏 已收藏
分享
返回顶部