This is what Android 5 comes out with.

First look at the renderings:

Individual element sharing Multiple elements shared

Single element sharing

Use:

MainActivity:

XML layout:

<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:onClick="imageClick"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher_round"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Copy the code

Kotlin code:

Main2Activity:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:ignore="MissingDefaultResource">

    <ImageView
        android:transitionName="shareElement"
        app:layout_constraintTop_toTopOf="parent"
        android:onClick="image2Click"
        android:src="@mipmap/ic_launcher_round"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_width="200dp"
        android:layout_height="200dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Copy the code

Auxiliary graph:

The two parameters must be consistent. This parameter indicates the page from PAGE A to page B

Page B returns to page A:

When page B returns to page A, finsh cannot be called directly. I am the physical return key of the call.

Multiple elements shared

Same idea, directly on the code:

Here are some things to note:

When passing parameters, do not use Pair in KT, use Pair in Java

Main2Activity page:

Do not need to do anything, just make sure that the parameters passed are consistent:

Take a look at the renderings: