Recyclerview 问题上的 Alpha 动画 - 淡化为零后弹出

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

还有一个问题。 我试图让 RecycleView 项目消失,所以我为每个项目编写了一个 XML 动画,然后是一个图层动画 XML 并在 Java main activity 中添加了代码。一切正常,视图消失了,但问题是,它们全部消失后,它们突然又自己出现了!可能是什么原因?如何保持 alpha 0?

代码:

主要activity方法:

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

物品动画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>

图层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%" />

您需要将 android:fillAfter="true" 属性 添加到项目动画 XML 以保持动画变化。

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