gpt4 book ai didi

android动画未在onAnimationEnd完成

转载 作者:IT老高 更新时间:2023-10-28 13:17:06 27 4
gpt4 key购买 nike

虽然 animation.hasEnded 设置为 true,但触发 onAnimationEnd 事件时,似乎 Android 动画并未真正完成。

我希望我的 View 在它的 ScaleAnimation 末尾更改它的背景可绘制对象,但您可以清楚地看到它在完成前几毫秒发生了更改。问题是,它会闪烁,因为新背景出现(=is)缩放了很短的时间,直到动画真正结束。

有没有办法让动画真正结束,或者只是阻止新背景在这么短的时间内缩放?

谢谢!


//编辑:我正在使用 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
}

最佳答案

这是与此问题相关的实际错误 http://code.google.com/p/android-misc-widgets/issues/detail?id=8

这基本上说明当 AnimationListener 附加到 Animation 时 onAnimationEnd 方法不能很好地工作

解决方法是在您将动画应用到的 View 中监听动画事件例如,如果最初您将动画监听器附加到这样的动画

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

然后将动画应用到像这样的 ImageView

mImageView.startAnimation(mAnimation);

要解决此问题,您现在必须创建自定义 ImageView

public class MyImageView extends ImageView {

然后重写 View 类的 onAnimationEnd 方法并提供那里的所有功能

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

这是解决此问题的正确解决方法,在覆盖的 View -> onAnimationEnd 方法中提供功能,而不是附加到动画的 AnimationListener 的 onAnimationEnd 方法。

这可以正常工作,并且在动画结束时不再有任何闪烁。希望这会有所帮助。

关于android动画未在onAnimationEnd完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4750939/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com