Software Engineer @ Acorns
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowSharedElementEnterTransition">
@transition/grid_detail_transition
</item>
<item name="android:windowSharedElementReturnTransition">
@transition/grid_detail_transition
</item>
</style>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<!-- changeBounds is used for the TextViews which are shared -->
<changeBounds />
<!-- changeImageTransform is used for the ImageViews which are shared -->
<changeImageTransform />
</transitionSet>
// defined in Screen B
val transition = TransitionInflater.from(context)
.inflateTransition(R.transition.grid_detail_transition)
sharedElementEnterTransition = transition
sharedElementReturnTransition = transition
<!-- Screen B -->
<ImageView
android:id="@+id/imageview_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionName="header:image"
android:scaleType="centerCrop" />
// Screen B
val headerImage = findViewById(R.id.mageview_header)
ViewCompat.setTransitionName(headerImage, "header:image")
// Screen A
val intent: Intent = Intent(this, DetailActivity::class.java)
val activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(
this,
Pair<View, String>(findViewById(R.id.imageview_item), "header:image"),
Pair<View, String>(findViewById(R.id.textview_name), "header:title")
ActivityCompat.startActivity(this, intent, activityOptions.toBundle())
// Screen A
val transition = TransitionInflater.from(context)
.inflateTransition(R.transition.grid_detail_transition)
fragmentTwo.setSharedElementReturnTransition(transition)
fragmentTwo.setSharedElementEnterTransition(transition)
val headerImage = findViewById(R.id.ivProfile)
val headerText = findViewById(R.id.ivProfile)
val ft = fragmentManager.beginTransaction()
.replace(R.id.container, fragmentTwo)
.addToBackStack("transaction")
.addSharedElement(headerImage, "header:image")
.addSharedElement(headerText, "header:text")
.commit()