最近看到一个项目上的界面切换时的过渡效果很炫,决定实现一下,先放上效果图:
效果就是在跳转到另一个Activity时 控件并没有消失,而是直接位移到指定位置,这个过渡效果就非常的自然,这就是”共享动画”。废话不多说,来看实现步骤
这边分为两个界面:MainActivity 和 ActivityDetails,从 MainActivity 跳转到 ActivityDetails
首先来说 MainActivity:
这边的列表我是用的 RecyclerView 来实现的,用RecyclerView来显示数据这个太简单就不用说了吧,注意,这里有个不同的地方在于在列表的 Item 布局文件中 还要稍微加一点东西
<?xml version="1.0" encoding="utf-8"?> xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="8dp"> android:id="@+id/layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="8dp"> android:id="@+id/image" android:layout_width="100dp" android:layout_height="100dp" android:transitionName="image" android:src="@mipmap/ic_launcher" />