Android动画闪烁

JRo*_*Rod 16 android android-animation

我一直在搜索关于这个主题的线索,我可以在Android 2.2处理AnimationListeners时出现的闪烁中找到,但我无法解决我的问题.

我得到的是一个LinearLayout'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);
    }

});
Run Code Online (Sandbox Code Playgroud)

Cri*_*ris 52

我有同样的问题,几天后我找到了解决方案... thanx to:

http://www.mail-archive.com/android-developers@googlegroups.com/msg67535.html

我找到了解决这个问题的方法.线索来自这样一个事实,即在展示视图时,一切正常.显然,当动画运行时,节目强制的更新会在后台发生,不会引起闪烁.当我们隐藏视图时,在onAnimationEnd()的后端添加一个短动画会使闪烁消失.

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

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


ste*_*mit 13

@Override
public void onAnimationEnd(Animation animation)
{
    footer.clearAnimation();
}
Run Code Online (Sandbox Code Playgroud)

这对我有用.


Ore*_*Ore 5

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

  • android:animateLayoutChanges="true"我的根 xml 元素中有
  • 当有问题的视图直接连接到根 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>
Run Code Online (Sandbox Code Playgroud)

, 做

<?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:layout_width="50dp"
        android:layout_height="50dp">

        <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>
    </LinearLayout>
    ...
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)