前言
Android从API19引入了Transition过渡动画框架,它通过场景Scene概念来表述动画的关键帧,只要提供了开始和结束场景的内容就会自动做动画。过渡动画其实是对属性动画的一种封装,它能够一次对多个对象做动画而不需要特别复杂的配置。除此之外Activity之间的切换效果也可以使用过渡动画来实现。
基础使用
首先需要定义Scene也就是场景对象,场景其实就是某个事件点所有的视图对象当前状态,这里先定义一个开始的场景。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp">
<ImageView
android:id="@+id/first"
android:background="@drawable/round_red"
android:layout_marginTop="20dp"
android:layout_marginLeft="50dp"
android:layout_gravity="top|left"
android:layout_width="100dp"
android:layout_height="100dp" />
<ImageView
android:id="@+id/second"
android:background="@drawable/round_green"
android:layout_marginTop="20dp"
android:layout_marginRight="50dp"
android:layout_gravity="top|right"
android:layout_width="100dp"
android:layout_height="100dp" />
<ImageView
android:id="@+id/third"
android:layout_gravity="bottom|left"
android:layout_marginBottom="20dp"
android:layout_marginLeft="50dp"
android:background="@drawable/round_yellow"
android:layout_width="100dp"
android:layout_height="100dp" />
<ImageView
android:id="@+id/forth"
android:layout_gravity="bottom|right"
android:layout_marginBottom="20dp"
android:layout_marginRight="50dp"
android:background="@drawable/round_blue"
android:layout_width="100dp"
android:layout_height="100dp" />
</FrameLayout>
scene1 = Scene.getSceneForLayout(mContainer, R.layout.scene_layout_one, this);
场景第一参数mContainer就是包含这个场景的根布局,后面的场