android - recyclerview 问题上的 Alpha 动画 - 淡入为零后弹回
问题描述
还有一个问题。我试图让 RecycleView 项目消失,所以我为每个项目编写了一个 XML 动画,然后是一个层动画 XML,并在 Java 主要活动中添加了代码。一切正常,视图消失了,但问题是,在它们全部消失后,它们突然又自行出现了!可能是什么原因?如何保持 alpha 0?
代码:
主要活动方式:
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"
向 Item 动画 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>
推荐阅读
- java - Spring MVC 不会映射到我的控制器
- python - 对 Pandas Dataframe 构造函数中的两个字段执行计算/算术运算
- javascript - Associate two keys in an object JavaScript
- java - 如何擦除单个路径的一部分?
- python - 使用“积分系统”打印数字的素数
- amazon-lex - 使用 EXPANDED VALUES 的 Amazon Lex 自定义槽类型问题
- express - 开玩笑的承诺没有解决
- wordpress - Cloud Launcher 的 WordPress 中的 .appspot.com 域
- vba - 如何分配箭头键ti图像以在用户周围移动
- postgresql - Kubernetes Citus setup with individual hostname/ip