在Recylerview中翻转动画

时间:2018-07-04 20:39:00

标签: android animation android-recyclerview

需求很简单,即单击按钮即可将翻转动画添加到Recylerviewrow并加载不同的数据集。但是问题是我没有为Recylerview获取正确的翻转动画资源。

This is the requirement only flip animation

我已尝试修改此代码 https://github.com/patrick-iv/Enter-animation-demo

动画代码:

<script>
  var nickname = "<%nickname%>";
  var room = "<%room%>";
</script>

item_animation_fall_down.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:delay="15%"
    android:animationOrder="normal" />

动画已添加到班级中:

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

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

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

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

当我尝试更改item_animation_fall_down.xml以添加翻转动画时,应用程序崩溃,提示

private void runLayoutAnimation(final RecyclerView recyclerView, final AnimationItem item) {
        final Context context = recyclerView.getContext();

        final LayoutAnimationController controller =
                AnimationUtils.loadLayoutAnimation(context, item.getResourceId());

        recyclerView.setLayoutAnimation(controller);
        recyclerView.getAdapter().notifyDataSetChanged();
        recyclerView.scheduleLayoutAnimation();
    }

翻转动画代码Flip animation

0 个答案:

没有答案