关于 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 应该如何计算呢?

解决方案 »

  1.   

    pivotXValue 和 pivotYValue不是中心点坐标吗?
    如果你的pivotYType = Animation.RELATIVE_TO_SELF的话,传0.5F吧
      

  2.   


    实际上是个简单的数学问题
    缩放的中心是绝对不变的 缩放前和缩放后都是不变的于是有如下等式成立
    xx/w = ( l + xx)/ SW = pivotXValue解得xx = (l * w) / ( SW - w )
    pivotXValue = l  / ( SW - w )同理
    pivotYValue = t  / ( SH - w )
      

  3.   


    实际上是个简单的数学问题
    缩放的中心是绝对不变的 缩放前和缩放后都是不变的于是有如下等式成立
    xx/w = ( l + xx)/ SW = pivotXValue解得xx = (l * w) / ( SW - w )
    pivotXValue = l  / ( SW - w )同理
    pivotYValue = t  / ( SH - w )更正 pivotYValue = t  / ( SH - h )