美文网首页
给RecyclerView 的子项添加入场动画

给RecyclerView 的子项添加入场动画

作者: fengfancky | 来源:发表于2019-12-19 17:13 被阅读0次

效果

子项按顺序显示


item_anim_order.gif

实现

创建动画xml
放在res/anim目录下

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1200">
    <alpha
        android:fromAlpha="0"
        android:toAlpha="1" />
    <translate
        android:fromYDelta="-100%p"
        android:toYDelta="0" />
</set>

创建layoutAnimation
放在res/anim目录下

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

animation :值为上一步创建的xml文件
delay:每项开始动画执行的相对延时,0%为同步,100%为上一个完全运行结束再开始
animationOrder:动画运行顺序,normal为顺序执行,reverse 为倒序执行,random为随机执行

设置RecyclerView的layoutAnimation

 android:layoutAnimation="@anim/rv_layout_anim"

实现效果。

相关文章

网友评论

      本文标题:给RecyclerView 的子项添加入场动画

      本文链接:https://www.haomeiwen.com/subject/cotvnctx.html