如何将ScaleAnimation缩放到特定大小

3
我有一个视图,其初始大小为(Width1和Height1)。我想创建动画将其大小更改为最终大小(Width2和Height2)。我一直在阅读有关ScaleAnimation的内容,但无法理解缩放因子。
请问构造函数中的值a,b,c和d是多少?
ScaleAnimation scaleAnimation = new ScaleAnimation(a, b, c, d);

谢谢

1个回答

2

4个浮点数构造函数的参数如下:

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 

所有的值都是浮点数--它们代表的不是像素大小,而是相对缩放因子。所以要从 width1 缩放到 width2 ,并从 height1 缩放到 height2 ,你需要设置:

ScaleAnimation scaleAnimation = 
   new ScaleAnimation(1f, 1f * width2 / width1, 1f, 1f * height2 / height1);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接