读书人

放大的动画怎么设置参数

发布时间: 2013-10-12 11:54:04 作者: rapoo

放大的动画如何设置参数?
关于 ScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue) 的参数如何设置的问题

我有个小图在屏幕的任意位置,假设四个位置点是 (l,t,r,b),宽度是w, 高度是h
屏幕的宽度是SW,高度是SH,w大概是SW的1/5~1/3之间, h/SH也是大概的比例。

当执行放大时,希望在原来的大小基础上,慢慢填满全屏,所以参数这样设置:
fromX = 1.0f
fromY = 1.0f
toX = SW/w
toY = SH/h
pivotYType = Animation.RELATIVE_TO_SELF
pivotYType = Animation.RELATIVE_TO_SELF

关键是 pivotXValue 和 pivotYValue 应该如何计算呢?



于是有如下等式成立
xx/w = ( l + xx)/ SW = pivotXValue

解得xx = (l * w) / ( SW - w )
pivotXValue = l / ( SW - w )

同理
pivotYValue = t / ( SH - w )

更正 pivotYValue = t / ( SH - h )

读书人网 >Android

热点推荐