android动画未在onAnimationEnd中完成

onAnimationEnd尽管将事件animation.hasEnded设置为true,但似乎在触发事件时并未真正完成android动画。


我希望我的视图在其结束时更改其背景可绘制的背景ScaleAnimation,但是您可以清楚地看到它在完成前几毫秒就被更改了。问题在于,它闪烁是因为新背景会在短时间内缩放,直到动画真正完成为止。


是否有办法获得动画的真实结尾,或者只是防止在短时间内缩放新背景?


谢谢!


//编辑:我正在使用AnimationListener来获取以下呼叫:


    @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

}


波斯汪
浏览 798回答 3
3回答

莫回无

我正在通过在onAnimationEnd内进行动画处理的视图上调用clearAnimation()来解决此问题,这消除了闪烁的原因,为什么有人必须这样做,因为仅当动画已经结束时才应调用onAnimationEnd回调。但是我想答案就在于Framework的深度,即视图/布局如何处理动画回调。现在,将其作为无黑客解决方案,就可以了。&nbsp; &nbsp; &nbsp; &nbsp; animation.setAnimationListener(new AnimationListener() {&nbsp; &nbsp; &nbsp; &nbsp; public void onAnimationEnd(Animation anim) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; innerView.clearAnimation();&nbsp; &nbsp;// to get rid of flicker at end of animation&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (innerBlockContainer.getWidth(), innerBlockContainer.getHeight());&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* Update lp margin, left/top to update layout after end of Translation */&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ViewGroup parent_ofInnerView = (ViewGroup)innerView.getParent();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; vp.updateViewLayout(innerBlockContainer, lp);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; public void onAnimationRepeat(Animation arg0) {}&nbsp; &nbsp; &nbsp; &nbsp; public void onAnimationStart(Animation arg0) {&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });

HUX布斯

我有一个类似的问题,我在自定义视图类中使用了Soham的解决方案。效果很好,但最后,我找到了一个对我有用的简单解决方案。调用了之后view.StartAnimation(animation),并在程序中进行下一步之前,我添加了一个短暂的延迟,该延迟足够长以使动画结束,但又足够短以使用户无法察觉:new Handler().postDelayed(new Runnable() {&nbsp; &nbsp; &nbsp; &nbsp;@Override&nbsp; &nbsp; &nbsp; &nbsp;public void run() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nextStepInMyProgram();&nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp;}, 200);// delay in milliseconds (200)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Android