机器人动画中没有onAnimationEnd完成 [英] android animation is not finished in onAnimationEnd

查看:284
本文介绍了机器人动画中没有onAnimationEnd完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来,当 onAnimationEnd 事件被触发,尽管 animation.hasEnded 的机器人动画是不是真正完成后,将设置为true。

我想我的观点的是改变它的背景绘制的结束 ScaleAnimation 这确实如此,但你可以清楚地看到,它改变了一些毫秒完成之前。的问题是,它闪烁,因为新的背景显示(=是)缩放很短的时间,直到动画确实完成

有没有办法让无论是动画的真正结束,或只是prevent从beeing缩放这短短的时间段的新的背景?

感谢您!


//编辑:我使用的是 AnimationListener 得到以下电话:

  @覆盖
公共无效onAnimationEnd(动画动画)
{
    查看查看=(MyView的)((ExtendedScaleAnimation)动画).getView();

    view.clearAnimation();
    view.requestLayout();
    view.refreshBackground(); //<  - 这是在后台得到改变
}
 

解决方案

下面是与此相关的问题<一个实际的错误href="http://$c$c.google.com/p/android-misc-widgets/issues/detail?id=8">http://$c$c.google.com/p/android-misc-widgets/issues/detail?id=8

这基本上指出onAnimationEnd方法并没有真正很好地工作时AnimationListener附加到动画

解决方法是听在观看动画的事件,你在申请的动画 例如,如果一开始你是连接动画监听到动画像这样

  mAnimation.setAnimationListener(新AnimationListener(){
    @覆盖
    公共无效onAnimationEnd(动画为arg0){
        //此处功能
    }
});
 

,然后应用到动画到这样一个ImageView的

  mImageView.startAnimation(mAnimation);
 

要解决此问题,你现在必须创建一个自定义的ImageView

 公共类MyImageView扩展ImageView的{
 

,然后覆盖View类的 onAnimationEnd 方法,并提供所有的功能,有

  @覆盖
保护无效onAnimationEnd(){
    super.onAnimationEnd();
    //此处功能
}
 

这是正确的解决此问题,提供的功能在过riden观点 - 而不是附着于动画的AnimationListener的onAnimationEnd法> onAnimationEnd方法

这工作是否正常,不再有对动画的结尾任何闪烁。希望这有助于。

It seems that an android animation is not truly finished when the onAnimationEnd event is fired although animation.hasEnded is set to true.

I want my view to change it's background drawable on the end of it's ScaleAnimation which it does, but you can clearly see that it is changed some miliseconds before it finishes. The problem is, that it flickers because the new background appears (=is) scaled for a short time until the animation really finishes.

Is there a way to get either the real end of the animation or just prevent the new background from beeing scaled this short period of time?

Thank you!


//EDIT: I'm using an AnimationListener to get the following call:

    @Override
public void onAnimationEnd(Animation animation)
{
    View view = (MyView) ((ExtendedScaleAnimation) animation).getView();

    view.clearAnimation();
    view.requestLayout();
    view.refreshBackground(); // <-- this is where the background gets changed
}

解决方案

Here is the actual bug related to this issue http://code.google.com/p/android-misc-widgets/issues/detail?id=8

This basically states that the onAnimationEnd method doesn't really work well when an AnimationListener is attached to an Animation

The workaround is to listen for the animation events in the view to which you were applying the animation to For example if initially you were attaching the animation listener to the animation like this

mAnimation.setAnimationListener(new AnimationListener() {
    @Override
    public void onAnimationEnd(Animation arg0) {
        //Functionality here
    }
});

and then applying to the animation to a ImageView like this

mImageView.startAnimation(mAnimation);

To work around this issue, you must now create a custom ImageView

public class MyImageView extends ImageView {

and then override the onAnimationEnd method of the View class and provide all the functionality there

@Override
protected void onAnimationEnd() {
    super.onAnimationEnd();
    //Functionality here
}

This is the proper workaround for this issue, provide the functionality in the over-riden View -> onAnimationEnd method as opposed to the onAnimationEnd method of the AnimationListener attached to the Animation.

This works properly and there is no longer any flicker towards the end of the animation. Hope this helps.

这篇关于机器人动画中没有onAnimationEnd完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆