如何获得这些动画开始的视图对象......?视图、如何获得、对象、动画

2023-09-06 03:32:56 作者:世界很宽,孤独很满

我在哪,我开始同样的动画3图像视图(翻译)

I have 3 image view in which i started same animation (translate)

我有动画的听众,在onAnimationEnd(动画动画)的方法,

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

在此先感谢..!

推荐答案

好了,你可以不知道什么是动画结束了它的对象。该AnimationListener的全部目的是为了听动画,而不是目标。

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.

解决方案

1 - 创建自己的动画类,并保存在它的引用,这是制作动画的对象

1- Create your own Animation class and save in it a reference to the object which is animating.

这将允许你施放动画YourAnimation在功能 onAnimationEnd 并获得借鉴。

This will allow you to cast the Animation to YourAnimation in the function onAnimationEnd and get the reference.

2 - 一个更简单的解决方案是创建你自己的AnimationListener,用于保存动画对象的引用

2- A simpler solution is to create your own AnimationListener that holds a reference of the Object that is animated.

例如:

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) {
    }
}

所以,当你想动画的ImageView的:你做到以下几点:

So when you want to animate your ImageView: You do the following:

MyAnimationListener listener = new MyAnimationListener();
listener.setImage(myImage);

myAnimation.setAnimationListener(listener);
 
精彩推荐
图片推荐