hello i saw this code that make a scale animation for a list view
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);
}
}
i know that this will make the animation from the center of the Activity not from the top-left point but i don’t understand where is these points are( -centerX,-centerY) and respect to what to the animation top-left corner or view !!
If you’re talking about the matrix operations, that’s quite simple: the basic setScale applies a scaling around the origin. So by pre-concatenating a translation of the specified centre point to the origin, and post-concatenating the opposite translation to move back to the centre point, you get a scaling around the centre point instead.