I wish to implement scale up animation on shared elements on activity transitions just like in this link .
But couldn't find any good reference for this specific effect and how to implement it. Is this a custom transition or a default ? Maybe anyone could help or post more detailed tutorial on this rather than official documentation .
Android also supports these shared elements transitions: changeBounds - Animates the changes in layout bounds of target views. changeClipBounds - Animates the changes in clip bounds of target views. changeTransform - Animates the changes in scale and rotation of target views.
Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.
At a high level, here's how to make a fragment transition with shared elements: Assign a unique transition name to each shared element view. Add shared element views and transition names to the FragmentTransaction . Set a shared element transition animation.
Let me give you a short tutorial right here :)
What you actually want is a Shared element transition between two activities. You'll not actually share any views, both activities will have independent view trees. But we'll pass the info about the shared element such as its view and its size to the new activity.
While launching, the new activity will make all its views transparent and locates the shared view. It alters its attributes to match those passed in from the launching activity and makes that single view visible. It then runs animations to transition the shared view from this state to its natural position in the layout. As the transition progresses, the window background and the rest of the non-shared elements slowly fade in until they're totally opaque. All of this is done automatically.
Now to mark a view as shared set this property:
<ImageView
...
android:transitionName="@string/transition_photo" />
in both the activity layouts.
Now while starting your new activity from old activity define a transition animation:
Bundle bundle = ActivityOptions.makeSceneTransitionAnimation(
this,
sharedView,
sharedView.getTransitionName())
.toBundle();
startActivity(intent,bundle);
You can also specify multiple views for transition. You can even transition shared views between different applications.
By default the animation used is move:
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeBounds/>
<changeTransform/>
<changeClipBounds/>
<changeImageTransform/>
</transitionSet>
But you can also set your custom animations in styles.xml:
<style name="AppTheme.Details">
<item name="android:windowSharedElementEnterTransition">@transition/shared_photo</item>
</style>
Here is a working example of shared element transition as shown above: https://github.com/anshchauhan/SharedElementTransition
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With