I have 3 image view in which i started same animation (translate)
I have animation listener, in onAnimationEnd(Animation animation) method,
I want to know on which image view the animation is ended..?
From animation object how can I know in which it was started..?
Thanks in advance..!
You can use the view animation system to perform tweened animation on Views. Tween animation calculates the animation with information such as the start point, end point, size, rotation, and other common aspects of an animation.
Well you can not know what is the object on which the animation ended. The whole purpose of the AnimationListener is to listen to the Animation and not to the object.
Solution
1- Create your own Animation class and save in it a reference to the object which is animating.
This will allow you to cast the Animation to YourAnimation in the function onAnimationEnd
and get the reference.
2- A simpler solution is to create your own AnimationListener that holds a reference of the Object that is animated.
For example:
public class MyAnimationListener implements AnimationListener {
ImageView view;
public void setImage(ImageView view) {
this.view = view;
}
public void onAnimationEnd(Animation animation) {
// Do whatever you want
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
}
So when you want to animate your ImageView: You do the following:
MyAnimationListener listener = new MyAnimationListener();
listener.setImage(myImage);
myAnimation.setAnimationListener(listener);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With