我有一个具有起始大小(Width1 和 Height1)的 View 。我想创建一个动画以将其大小更改为最终大小(Width2 和 Height2)。我一直在阅读有关 ScaleAnimation 的内容,但我无法理解比例因子。
你能告诉我构造函数的值 a、b、c 和 d 吗:
ScaleAnimation scaleAnimation = new ScaleAnimation(a, b, c, d);
谢谢
最佳答案
4-floats ScaleAnimation 构造函数的参数如下:
fromX Horizontal scaling factor to apply at the start of the animation
toX Horizontal scaling factor to apply at the end of the animation
fromY Vertical scaling factor to apply at the start of the animation
toY Vertical scaling factor to apply at the end of the animation
所有值都是 float ——它们不是以像素为单位表示大小,而是相对比例因子。
因此,要从 width1
缩放到 width2
以及从 height1
缩放到 height2
您需要设置:
ScaleAnimation scaleAnimation =
new ScaleAnimation(1f, 1f * width2 / width1, 1f, 1f * height2 / height1);
关于android - 如何将动画缩放到特定大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22895195/