页面A和页面B共享一个元素,当从页面A跳转到页面B时,使页面A上的共享元素通过调整大小和位置,直接变换到页面B上
页面A上放置一个image,transitionName设置为sharedImage
<ImageView
android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:transitionName="sharedimage" />
页面B上也放置一个image,transition同样设置为sharedImage
<ImageView
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
android:transitionName="sharedimage" />
在页面跳转时指定共享元素
ImageView imageView = findViewById(R.id.imageview);
Intent intent = new Intent().setClass(this, Main2Activity.class);
startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this, imageView, "sharedimage").toBundle());