Android 如何在更改布局管理器时设置回收器视图的动画

Android 如何在更改布局管理器时设置回收器视图的动画,android,android-recyclerview,android-animation,gridlayoutmanager,linearlayoutmanager,Android,Android Recyclerview,Android Animation,Gridlayoutmanager,Linearlayoutmanager,在我的应用程序设计中,我需要将回收器视图的布局管理器从线性水平更改为网格布局管理器 我需要让这个转变顺利进行。 任何人都可以建议我如何使之成为可能。为了使布局管理器的更改具有动画效果,您需要在回收视图上应用布局动画,为此,您需要遵循以下步骤: 1) 创建项目动画文件以设置项目出现的动画 item_animation.xml <set xmlns:android="http://schemas.android.com/apk/res/android" android:duration

在我的应用程序设计中,我需要将回收器视图的布局管理器从线性水平更改为网格布局管理器

我需要让这个转变顺利进行。
任何人都可以建议我如何使之成为可能。

为了使布局管理器的更改具有动画效果,您需要在
回收视图上应用布局动画,为此,您需要遵循以下步骤:

1) 创建项目动画文件以设置项目出现的动画

item_animation.xml

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

    <translate
        android:fromYDelta="-30%"
        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="115%"
        android:fromYScale="115%"
        android:toXScale="100%"
        android:toYScale="100%"
        android:pivotX="50%"
        android:pivotY="50%"
        android:interpolator="@android:anim/decelerate_interpolator"
        />

</set>

感谢您的回答,但您发送的代码与普通动画一样工作。我想要的是以一种平滑的方式将回收者视图项目动画化到它们的新位置,就像共享元素转换一样。好的,我会检查并返回给你。@PavanVarma,你找到过这种共享转换效果的解决方案吗?你找到了解决方案吗?没有,我仍然没有找到任何东西@Hala.MDid有人试图只使用网格并将spanCount设置为1,而您需要显示为列表?在这种情况下,栅格会自动设置动画吗?
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
    android:animation="@anim/item_animation"
    android:animationOrder="normal"
    android:delay="15%" />
   private void runLayoutAnimation(final RecyclerView recyclerView) {
            final Context context = recyclerView.getContext();
            final LayoutAnimationController controller =
                    AnimationUtils.loadLayoutAnimation(context, R.anim.layout_animation);

            recyclerView.setLayoutAnimation(controller);
            recyclerView.getAdapter().notifyDataSetChanged();
            recyclerView.scheduleLayoutAnimation();
}
            // Changing the layout manager followed by applying the animation
            recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
            runLayoutAnimation(recyclerView);