java - 将 ImageView 的大小调整为另一个 ImageView 的大小的动画
问题描述
我有一张想要制作动画并移动到另一个 ImageView 位置的图片。
目前这就是我正在做的事情:
v.animate()
.scaleX(??)
.scaleY(??)
.x(target.x)
.y(target.y)
.setDuration(1000)
.start()
我的问题是如何计算 x 和 y 的正确比例因子?如果我将布局参数设置为等于目标的布局参数,那么它可以正常工作,但它不是动画的。我尝试将源图像的宽度和高度与目标图像相除,但它并没有给我正确的比例。
谢谢你的帮助
解决方案
为两个图像之间的比率创建一个浮点值:
float w_ratio = (targetImage.getMeasuredWidth() - sourceImage.getMeasuredWidth()) / sourceImage.getMeasuredWidth();
float h_ratio = (targetImage.getMeasuredHeight() - sourceImage.getMeasuredHeight()) / sourceImage.getMeasuredHeight();
// then animate:
v.animate().scaleXBy(w_ratio).scaleYBy(h_ratio).setDuration(1000);
// Don't forget to reset the size later if needed, using:
v.setScaleX(1.0f);
v.setScaleY(1.0f);
推荐阅读
- javascript - Multer 在上传文件时抛出错误
- node.js - req.user 是否保证是有效的、经过身份验证的用户?[护照.js]
- json - 将简单的 json 数组转换为纯文本
- django-rest-framework - 如何覆盖 APIView 中的 get_serializer_class 以根据特定条件更改基于类的视图中的 serializer_class 属性。?
- python - 有没有办法优化熊猫中的 itterrows 代码?
- python - 如何解决 python 脚本中找不到文件的问题?
- android - 检索在 MainActivity 类的另一个类中设置的意图额外键值
- mysql - 为 MYSQL 中某个时间段内的每一天添加行
- r - R rmcorr 不正确的自由度数
- javascript - 为什么 Node.js 垃圾收集器不收集 new Function() 的“编译代码”?