Android TranslateAnimation 在动画后重置 [英] Android TranslateAnimation resets after animation

查看:28
本文介绍了Android TranslateAnimation 在动画后重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建类似 SlideDrawer 的东西,但大多数自定义功能基本上都在工作,但动画在最后闪烁.

I'm creating something like a SlideDrawer but with most customization, basically the thing is working but the animation is flickering at the end.

为了进一步解释,我得到了一个 TranslateAnimation 然后在这个动画之后它返回到原始位置,如果我设置 setFillAfter 则布局内的按钮停止工作.如果我听 onAnimationEnd 并将其他人的布局设置为 View.GONE 布局错误.由此判断,在动画结束时,视图会回到调用View.GONE之前的原始位置.

To further explain, I got an TranslateAnimation then after this animation it returns back to the original position, if i set setFillAfter then the buttons inside the layout stops working. If i listen to onAnimationEnd and set other's layout to View.GONE the layout fickers. Judging from it is that on animation end, the view goes back to original position before the View.GONE is called.

任何建议都会很棒.谢谢

Any advice would be awesome. Thanks

推荐答案

这里是与此问题相关的实际错误

Here is the actual bug related to this issue

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

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
    }

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

and then applying to the animation to a ImageView like this

mImageView.startAnimation(mAnimation);

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

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

public Class myImageView extends ImageView {

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

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

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

这是解决此问题的正确方法,在覆盖的视图中提供功能 -> onAnimationEnd(...) 方法而不是 onAnimationEnd(...) 附加到 Animation 的 AnimationListener 的方法.

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

这篇关于Android TranslateAnimation 在动画后重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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