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

问题描述

我一直在搜索关于这个主题的尽可能多的线程,我可以在处理 AnimationListeners 时在 Android 2.2 中找到的闪烁中找到,但我不能完全解决我的问题.

I've been trawling through as many threads on this topic that I can find on the flicker that arises in Android 2.2 when dealing with AnimationListeners, but I can't quite solve my issue.

我得到的是一个 LinearLayout 'popover',用户触摸它向下移动大约 100 像素,然后再次触摸它向上移动.我终于让它在没有任何闪烁的情况下在第一部分工作(感谢在动画视图上调用 clearAnimation() 的建议),但是当做相反的事情(即,将视图向上移动)时,有一个闪烁开始.我真的不能在 onAnimationStart() 方法中调用 clearAnimation() 因为它不会动画!

What I've got is a LinearLayout 'popover' that the user touches to move down about 100 pixels, and touches again to move it back up. I've finally got it working on the first part without any flicker (thanks to the suggestion to call clearAnimation() on the view being animated), but when doing the opposite (ie, moving the view back up), there's a flicker at the start. I can't really call clearAnimation() in the onAnimationStart() method as it won't animate!

当然,如果我在没有任何动画侦听器的情况下使用 setFillAfter() ,所有动画都可以完美运行,但是视图的触摸区域将不会移动(因为视图本身并没有实际"移动).

Of course, all animation works perfectly if I used setFillAfter() without any animation listener, but then the view's touch area won't move (because the view itself hasn't "actually" moved).

任何帮助将不胜感激.

this.popoverTab.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        popoverTab.setClickable(false);
        popoverTab.setFocusable(false);
        if (popoverHidden) {
            Log.d(TAG, "About to show popover");
            // the popover is currently hidden, show it.
            TranslateAnimation animation = new TranslateAnimation(0, 0, 100, 0);
            animation.setDuration(700);
            animation.setFillBefore(true);
            animation.setAnimationListener(new AnimationListener() {
                public void onAnimationEnd(Animation animation) {

                }

                public void onAnimationRepeat(Animation animation) {

                }

                public void onAnimationStart(Animation animation) {
                    footer.layout(footer.getLeft(), (footer.getTop() - 100), footer.getRight(), footer.getBottom());
                }
            });
            footer.startAnimation(animation);
        } else {
            Log.d(TAG, "About to hide popover");
            // the popover is showing, hide it.
            TranslateAnimation animation = new TranslateAnimation(0, 0, 0, 100);
            animation.setDuration(700);
            animation.setFillAfter(true);
            animation.setAnimationListener(new AnimationListener() {
                public void onAnimationEnd(Animation animation) {
                    footer.clearAnimation();
                    footer.layout(footer.getLeft(), (footer.getTop() + 100), footer.getRight(), footer.getBottom());
                }

                public void onAnimationRepeat(Animation animation) {

                }

                public void onAnimationStart(Animation animation) {

                }
            });
            footer.startAnimation(animation);
        }
        // invert.
        popoverHidden = !popoverHidden;
        popoverTab.setClickable(true);
        popoverTab.setFocusable(true);
    }

});

推荐答案

我遇到了同样的问题,几天后我找到了解决方案......感谢:

I had the same problem and after few days I found the solution ... thanx to:

http://www.mail-archive.com/[email protected]/msg67535.html

我想出了解决这个问题的办法.线索来自事实在显示视图时,一切正常.显然,当动画运行时,更新将是表演强迫发生在后台,不会导致闪烁.在后端添加一个简短的动画当我们隐藏视图时 onAnimationEnd() 使闪烁消失离开.

这是工作代码中的新 onAndimationEnd()

Here is the new onAndimationEnd() in the working code

  public void onAnimationEnd(Animation animation) {
            animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f);
            animation.setDuration(1);
            mPlayer0Panel.startAnimation(animation);
   }

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

08-07 00:00