当出现回收视图项目时,如何设置其动画?
只有在设置回收器数据后添加或删除数据时,默认项animator才会设置动画.我正在开发新的应用程序,不知道从哪里开始.
有什么办法可以做到这一点吗?
当出现回收视图项目时,如何设置其动画?
只有在设置回收器数据后添加或删除数据时,默认项animator才会设置动画.我正在开发新的应用程序,不知道从哪里开始.
有什么办法可以做到这一点吗?
仅使用XML使其变得简单
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" />