Shared element transition between activities
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:windowContentTransitions">true</item> <!-- ADD THIS LINE-->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
<ImageView
android:id="@+id/ivProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="center"
android:src="@mipmap/ic_launcher"
android:transitionName="profile"/>
<ImageView
android:id="@+id/ivProfile"
android:layout_width="match_parent"
android:layout_height="380dp"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher"
android:transitionName="profile"/>
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ivProfile.setOnClickListener(View.OnClickListener {
val intent = Intent(this, DetailActivity::class.java)
val options = ActivityOptionsCompat.makeSceneTransitionAnimation(this, ivProfile, "profile")
startActivity(intent, options.toBundle())
})
}
}