开发者

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

开发者 https://www.devze.com 2023-04-08 12:44 出处:网络
I have 3 image view in which i started sa开发者_运维百科me animation (translate) I have animation listener, in onAnimationEnd(Animation animation) method,

I have 3 image view in which i started sa开发者_运维百科me 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..!


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消