0

你好,我看到这段代码为列表视图制作比例动画

public class ViewAnimation extends Animation {
float centerX, centerY;
public ViewAnimation3(){}
@Override
public void initialize(int width, int height, int parentWidth, int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
centerX = width/2.0f;
centerY = height/2.0f;
setDuration(2500);
setFillAfter(true);
setInterpolator(new LinearInterpolator());
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final Matrix matrix = t.getMatrix();
matrix.setScale(interpolatedTime, interpolatedTime);
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}

我知道这将使 Activity 中心的动画而不是左上角的动画,但我不明白这些点在哪里(-centerX,-centerY)并且尊重动画左上角的内容或查看!

4

1 回答 1

0

如果您在谈论矩阵运算,那很简单:基本的 setScale 围绕原点应用缩放。因此,通过将指定中心点的平移预先连接到原点,并后连接相反的平移以移回中心点,您将获得围绕中心点的缩放。

于 2012-04-25T03:05:25.970 回答