TransitionManager用于Scene场景之间的过渡
1.场景过渡有两个触发方式
go() 和 beginDelayedTransition()
2.常见的过渡效果有 : Fade Slide Explode ChangeBounds
(1)go()使用该方法是进行两个布局之间的切换,提前设置好两个布局,然后进行切换。
举例说明:
Main.layout 在Framelayout中插入要进行切换的布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/btn" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <FrameLayout android:id="@+id/root" android:layout_width="match_parent" android:layout_height="wrap_content" > <include layout="@layout/demo1"/> </FrameLayout> </LinearLayout>
要切换的布局如下:
demo01.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="300dp" android:id="@+id/root"> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher" /> </RelativeLayout>
demo02.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="300dp" android:id="@+id/root"> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:src="@mipmap/ic_launcher" /> </RelativeLayout>
执行代码如下: