Android动画闪烁

Android动画闪烁,android,android-animation,Android,Android Animation,关于这个话题,我已经浏览了很多帖子,在Android 2.2处理AnimationListeners时出现的闪烁,但我不能完全解决我的问题 我得到的是一个线性布局的“popover”,用户触摸它向下移动大约100像素,然后再次触摸它向上移动。我终于让它在第一部分没有任何闪烁的情况下工作了(多亏了对正在设置动画的视图调用clearAnimation()的建议),但是当执行相反的操作(即,将视图向后移动)时,在开始时会有闪烁。我不能在onAnimationStart()方法中调用clearAnima

关于这个话题,我已经浏览了很多帖子,在Android 2.2处理AnimationListeners时出现的闪烁,但我不能完全解决我的问题

我得到的是一个线性布局的“popover”,用户触摸它向下移动大约100像素,然后再次触摸它向上移动。我终于让它在第一部分没有任何闪烁的情况下工作了(多亏了对正在设置动画的视图调用clearAnimation()的建议),但是当执行相反的操作(即,将视图向后移动)时,在开始时会有闪烁。我不能在onAnimationStart()方法中调用clearAnimation(),因为它不会设置动画

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

任何帮助都将不胜感激

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);
    }

});

您不必在
onAnimationEnd()
上使用
clearAnimation()

试试这个:

  • 上同时使用
    setFillBefore(true)
    setFillAfter(true)
  • 在开始和结束动画时设置正确的布局属性

  • 我也有同样的问题,几天后我找到了解决办法。。。thanx至:

    我想出了解决这个问题的办法。线索来自事实 当显示视图时,一切正常。 显然,当动画运行时 由节目强制在后台进行,不会导致 闪烁。将短动画添加到动画的后端 onAnimationEnd()当我们隐藏视图时,会使闪烁消失 走开

    下面是工作代码中的新OnAndMationEnd()

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

    Alrite,我也有同样的问题让我搜索它,我最终在这篇文章。为我的问题找到了解决方案,想与大家分享我的解决方案

    我有很多动画正在运行,但最近开始闪烁,但当我跟踪问题时发现闪烁发生在绘制for循环下的动画列表之后。(数组列表)


    我只是简单地添加了try-catch,以便在找到问题后避免该问题;一些动画被动态删除,但没有足够的时间更新线程,因此循环仍然尝试并失败,但没有显示,而是闪烁,但在数组列表绘图的“尝试并捕获”下修复了我的问题

    我搜索了所有stackoverflow帖子的动画问题(闪烁和迟缓)。 我没有找到任何完美的答案。但我找到了同样的解决方案,如下所示

    开始使用动画时

    view_you_want_to_animate.setDrawingCacheEnabled(true);
    
    view_you_want_to_animate.setDrawingCacheEnabled(false);
    
    在动画使用方面

    view_you_want_to_animate.setDrawingCacheEnabled(true);
    
    view_you_want_to_animate.setDrawingCacheEnabled(false);
    
    现在,当我的视图设置动画时,我的视图没有闪烁或迟缓的行为。 它对我很有效

    @Override
    public void onAnimationEnd(Animation animation)
    {
        footer.clearAnimation();
    }
    

    这对我来说很有效。

    我遇到了同样的错误,但它只出现在一些视图中,尽管所有视图都有相同的实现。事实证明,发生这种情况有两个原因:

    • 当我在根xml元素中有
      android:animateLayoutChanges=“true”
    • 当有问题的视图直接连接到根xml元素时
    因此,有两种解决方案,要么删除
    android:animateLayoutChanges=“true”
    标记(建议您不要使用它),要么在有问题的视图周围使用包装器布局!因此,不是:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:animateLayoutChanges="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <LinearLayout
            android:id="@+id/btnClose"
            android:layout_width="50dp"
            android:layout_height="50dp">
    
            <ImageView
                android:layout_width="32dp"
                android:layout_height="32dp"
                android:layout_gravity="center"
                android:src="@drawable/ic_arrow_back" />
        </LinearLayout>
    ...
    </RelativeLayout>
    
    
    ...
    
    ,做

    
    ...
    
    将面板向后移动时,我仍然会闪烁。我在它后面放了一个虚拟视图,其中包含与前面相同的内容。我也遇到了同样的问题,调整view.layout()似乎会导致闪烁。非常感谢您解决了这个问题!非常感谢。我花了很长时间才找到这个。我有眨眼的问题(我不知道眨眼和眨眼是不是一回事),这就解决了这个问题。在搜索了很长时间后,这节省了我的时间。它在我的项目中起作用,它使用浮动动作按钮,使用反弹(Facebook)和背板(Tumblr)。这对我也起作用,使用独立alpha动画和平移+缩放动画集。不推荐使用setDrawingCacheEnabled。此线程中的一个被低估的答案。动画后“我的视图”闪烁的原因是由于android:animateLayoutChanges=“true”。我认为它与
    转换重叠
    编程编码。删除android:animateLayoutChanges=“true”解决了我的问题。