Android Animation Flicker

前端 未结 6 1369
天命终不由人
天命终不由人 2020-11-30 11:17

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

相关标签:
6条回答
  • 2020-11-30 11:41

    Alrite, I had the same issue that made me search for it, I ended up in this post. Found a solution for my issue, thought to share my solution.

    I had many animations running but flickering started recently, but when I traced the issue found the flickering occured after drawing list of animations under a for loop. (array List)

    I simply added try catch to avoid the issue after locating it, the problem; some of the animations were removed on fly but there were not enough time for a thread to update, so the loop still tried and failed but not shown instead it flickered, but under try and catch on the array list drawing fixed my issue.

    0 讨论(0)
  • 2020-11-30 11:47

    I faced the same error, but it only appeared in some views, although all had the same implementation. As it turned out, it happened for two reasons:

    • When I had android:animateLayoutChanges="true" in my root xml element
    • When the problematic view was directly connected to the root xml element

    So, two solutions, either remove the android:animateLayoutChanges="true" tag (suggested since you're not using it), or use a wrapper Layout around the problematic view! So instead of:

    <?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>
    

    , do

    <?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>
    
    0 讨论(0)
  • 2020-11-30 11:52

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

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

    I figured out a solution to this problem. The clue came from the fact that when showing the view, everything worked fine. Apparently, when the animation is running, the update that would be forced by the show happens in the background and doesn't cause the flicker. Adding a short animation to the back end of the onAnimationEnd() when we are hiding the view makes the flicker go away.

    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);
       } 
    
    0 讨论(0)
  • 2020-11-30 11:55
    @Override
    public void onAnimationEnd(Animation animation)
    {
        footer.clearAnimation();
    }
    

    This worked for me.

    0 讨论(0)
  • 2020-11-30 12:02

    You shouldn't have to use clearAnimation() on onAnimationEnd().

    Try this:

    1. Use setFillBefore(true) and setFillAfter(true) on both animations
    2. Set the correct layout properties when starting and when ending both animations
    0 讨论(0)
  • 2020-11-30 12:06

    I searched for all stackoverflow posts for animation issue (flicker and sluggish). I didnt find any perfect answer. But I have found the solution for the same, which is as below,

    onStart of Animation use,

    view_you_want_to_animate.setDrawingCacheEnabled(true);
    

    onEnd of Animation use,

    view_you_want_to_animate.setDrawingCacheEnabled(false);
    

    Now my view does not have flicker or sluggish behavior when my view is animating. It works well for me.

    0 讨论(0)
提交回复
热议问题