当出现回收视图项目时,如何设置其动画?

只有在设置回收器数据后添加或删除数据时,默认项animator才会设置动画.我正在开发新的应用程序,不知道从哪里开始.

有什么办法可以做到这一点吗?

推荐答案

仅使用XML使其变得简单

Visit Gist Link

res/anim/layout_animation.xml

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

res/anim/item_animation_fall_down.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="500">

    <translate
        android:fromYDelta="-20%"
        android:toYDelta="0"
        android:interpolator="@android:anim/decelerate_interpolator"
        />

    <alpha
        android:fromAlpha="0"
        android:toAlpha="1"
        android:interpolator="@android:anim/decelerate_interpolator"
        />

    <scale
        android:fromXScale="105%"
        android:fromYScale="105%"
        android:toXScale="100%"
        android:toYScale="100%"
        android:pivotX="50%"
        android:pivotY="50%"
        android:interpolator="@android:anim/decelerate_interpolator"
        />

</set>

在布局和重新定位视图中使用,如下所示:

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layoutAnimation="@anim/layout_animation"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

Android相关问答推荐

请求标头为空/无法通过拦截器获取

学习Kotlin问题.无法理解Modifier参数

Android 构建失败:找不到 flexbox2.0.1.aar

当 Jetpack Compose 中的第一个文本很长时,将省略号添加到第一个文本

我如何比较多个时间范围并在 Android Compose 中并排显示它们

是否可以按照干净的体系 struct 将活动实例传递给视图模型

修复错误 Invariant Violation: requireNativeComponent: "RNSScreenStackHeaderConfig" was not found in the UIManager

在 Kotlin 中设置 startActivity() 时类型不匹配

在移动设备上看到时如何增加 PasswordField 文本?

我该怎么做文本计时器

如何从日期 Select 器计算年龄?

将房间中的实体更新为 isCompleted 并使用 Flow 问题获取所有数据

如何修复 api 调用在浏览器中工作但在 android studio 中为 403

Android Jetpack Compose - 每次文本字段值更改时,可组合函数都会重新组合

如何在 Android 上移动 EditText 上的图标?

Kotlin:如何在另一个变量的名称中插入一个变量的值

如何在 flow.stateIn() 之后从流中的另一个函数发出emits ?

未使用的内容填充参数

如何安装 Bumblebee 2021.1.1 Android Studio 补丁?

如何从片段(fragment)中获取工具栏?