Understanding Android TransitionManager

Android TransitionManager
0 115

Get real time updates directly on you device, subscribe now.

2 min read

TransitionManager class which was added in Android API level 19, manages the set of transitions that fire when there is a change of SCENE

To use the TransitionManager, you have to add the scenes along with the associated transition objects with calls to setTransition(Scene, Transition)or setTransition(Scene, Scene, Transition).

It is not a mandate to set specific transitions for scene changes; a Scene change in this scenario will use AutoTransition. AutoTransition is a utility class for creating a default transition that automatically fades, moves, and resizes views during a scene change.

An AutoTransition can be described in a resource file by using the tag autoTransition, along with the other standard attributes of Transition.

Specifying other transitions for particular scene changes is only necessary if the application wants different transition behavior in these situations.

TransitionManagers can be declared in XML resource files inside the res/transition directory. TransitionManager resources consist of the transitionManager tag name, containing one or more transition tags, each of which describe the relationship of that transition to the from/to scene information in that tag. For example, here is a resource file that declares several scene transitions:

<transitionManager xmlns:android="http://schemas.android.com/apk/res/android">
    <transition android:fromScene="@layout/transition_scene1"
                android:toScene="@layout/transition_scene2"
                android:transition="@transition/changebounds"/>
    <transition android:fromScene="@layout/transition_scene2"
                android:toScene="@layout/transition_scene1"
                android:transition="@transition/changebounds"/>
    <transition android:toScene="@layout/transition_scene3"
                android:transition="@transition/changebounds_fadein_together"/>
    <transition android:fromScene="@layout/transition_scene3"
                android:toScene="@layout/transition_scene1"
                android:transition="@transition/changebounds_fadeout_sequential"/>
    <transition android:fromScene="@layout/transition_scene3"
                android:toScene="@layout/transition_scene2"
                android:transition="@transition/changebounds_fadeout_sequential"/>
</transitionManager>

For each of the fromScene and toScene attributes, there is a reference to a standard XML layout file.

For the transition attribute, there is a reference to a resource file in the res/transition directory which describes that transition.