views:

359

answers:

1

I would like to obtain the transformation matrix of an animation to calculate the position of the view that was animated.

It seems the Animation class has a method called getTransformation that can be used to obtain the transformation applied to the view.

However, if I use getTransformation before starting the animation I obtain the identity matrix. And if I use it like this:

public void onAnimationEnd(Animation animation) {
    Transformation t = new Transformation();
    animation.getTransformation(animation.getDuration(), t);
}

The program enters an infite loop because getTransformation seems to trigger onAnimationEnd (why?).

How should I use getTransformation to obtain the transformation matrix of an animation? Is there another way to do this?

A: 

Because, for some reason, that is the way getTransformation is coded.

http://www.netmite.com/android/mydroid/1.5/frameworks/base/core/java/android/view/animation/Animation.java

It looks like you can check hasEnded() to see if the animation is complete. Try something like this:

public void onAnimationEnd(Animation animation)
{
   if ( animation.hasEnded() )
       return;

   Transformation t= new Transformation();
   animation.getTransformation(animation.getDuration(), t);
}
CShipley