I have to animate a view from state A to B with changes to its scale, position and scrolling. I know everything about state A (widthA, heightA, topA, leftA, scrollXA, scrollYA) and state B (widthB, heightB, topB, leftB, scrollXB, scrollYB).
So far I wrote the following code:
AnimationSet animation = new AnimationSet(true);
int toXDelta; // What goes here?
int toYDelta; // What goes here?
TranslateAnimation translateAnimation = new TranslateAnimation(1, toXDelta, 1, toYDelta);
translateAnimation.setDuration(duration);
animation.addAnimation(translateAnimation);
float scale = (float) widthB / (float) widthA;
ScaleAnimation scaleAnimation = new ScaleAnimation(1, scale, 1, scale);
scaleAnimation.setDuration(duration);
animation.addAnimation(scaleAnimation);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation arg0) {
view.clearAnimation();
// Change view to state B
}
@Override public void onAnimationRepeat(Animation arg0) {}
@Override public void onAnimationStart(Animation arg0) {}
});
view.startAnimation(animation);
Is this the right way to do this?
If so, how should I calculate the values of toXDelta and toYDelta? I'm having trouble finding the exact formula.
Thanks!