According to android documentation, shared elements transition determine how views that are shared between two activities transition between these activities. For example, if two activities have the same image in different positions and sizes, the changeImageTransform shared element transition translates and scales the image smoothly between these activities.
This thread looks at examples and libraries relating to Shared Transitions in android. Feel free to contribute more examples, links and libraries.
Oclemy
Easily Implement Shared Transition on Images
You can easily implement shared element transition on images using this library known as Transitional ImageView.
Let’s show you how to.
Step 1 – Install the Library
First register jitpack as a repository in your app level build.gradle:
Then install the library:
Step 2
Create Transitional ImageView in your layout by pasting the following code:
Step 3
Now build a TransitionImageObject and set it to the TransitionalImageView:
Full Example
Here is a beautiful example for using this library.
(a). Shoe.java
The model class to define a single shoe.
(b). ShoeAdapter.java
Then the recyclerview adapter.
(c). ShoeListActivity.java
The shoe list activity:
(d). MainActivity.java
And finally the main activity.
Demo
Here is the demo of what you get when you run the project.
Download
Here are the download links.
Oclemy
Kotlin Shared Transition RecyclerView and Fragments
This is also a simple shared transitions example written in Kotlin. This time round however a recyclerview is the shared element among two fragments.
Tools
Here are the things to keep in mind:
1. Create Transitions
In a folder known as transitions under resources add the following:
(a). change_bounds.xml
(b). change_image_transform.xml
Then:
2. Design Layouts
You will find the layouts in the code.
3. Write Code
Code is written in Kotlin in this case.
(a). Fragment1.kt
Here is the code for the first fragment.
(b). Fragment2.kt
Add the following code in second fragment.
(c). ScndActivity.kt
Then the second activity.
(d). MainActivity.kt
And lastly the main activity,
Demo
Here is what you get when you run the project.
Download
Oclemy
Java Shared Transition with Fragments and FloatingActionButton
This is a simple one-class example to utilize a shared element transition within fragments in an android activity. The programming language is Java. While it is not written in androidx, you can easily update it to androidx fragments and it doesn’t utilize any third partt library.
shared
Transitions
These are written in XML. Tyically you create a transition resource directory and place the XML.
(a). shared_enter_transition.xml
Here is the code:
Activities
Here are the activities
(a). MainActivity.java
Here is the main activity:
Demo
Here is the demo of what you get when you run the project.
Download Links