androidandroid-animationandroid-transitions

Alpha animation on recyclerview problem - after fades to zero pops-up back


one more problem. I am trying to make RecycleView items fade away, so I wrote an XML animation for each item, then a layer animation XML and added code in Java main activity. Everything works ok, views disappear, but the problem is, after they all disappear, they all of a sudden appear back again on their own! What can be the reason? How to keep alpha 0?

Codes:

Main activity method:

private void layoutDisappear(final RecyclerView recyclerView) {
        if(recyclerView.isAnimating()){
            return;
        }
        final Context context = recyclerView.getContext();
        final LayoutAnimationController controller =
                AnimationUtils.loadLayoutAnimation(context, R.anim.layout_recycleview_disappear);


        recyclerView.setLayoutAnimation(controller);
        recyclerView.setLayoutAnimationListener(new Animation.AnimationListener() {
                                       public void onAnimationStart(Animation animation) {}
                                       public void onAnimationRepeat(Animation animation) {}
                                       public void onAnimationEnd(Animation animation) {
                                       }
                                   });
                recyclerView.scheduleLayoutAnimation();

Item animation XML:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1400">
    <alpha
        android:fromAlpha="1"
        android:interpolator="@android:anim/decelerate_interpolator"
        android:toAlpha="0" />
    <scale
        android:fromXScale="100%"
        android:fromYScale="100%"
        android:interpolator="@android:anim/decelerate_interpolator"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="102%"
        android:toYScale="102%" />
</set>

Layer XML:

<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
    android:animation="@anim/item_recycleview_disappear"
    android:animationOrder="reverse"
    android:delay="7%" />

Solution

  • You need add android:fillAfter="true" property to Item animation XML to keep animation changes.

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:fillAfter="true"
        android:duration="1400">
        ...
    </set>