Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get View object on which animation was started......?

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..!

like image 945
Noby Avatar asked Sep 27 '11 12:09

Noby


People also ask

How do you view animations?

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.


1 Answers

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);
like image 103
Sherif elKhatib Avatar answered Oct 01 '22 04:10

Sherif elKhatib