Skip to content

Guide · Open source

How to use Material-Animations: Android transition examples

Updated · written with AI from the project's own documentation and checked against our catalogue data

Material-Animations is an open-source reference project by lgvalle that explains and demonstrates Android's Transition Framework, the system for animating screens and views. It is aimed at Android developers and students learning how activity transitions work. After this guide you will know what the project covers, how to get it running, and how the Explode, Slide and Fade transitions and shared elements are set up in code.

Material-Animationslgvalle/Material-Animations · ★ 13.5k · MIT

Quick start

  1. 1Check prerequisites. Install Android Studio and make sure you have Java available.
  2. 2Clone the repository. Run git clone https://github.com/lgvalle/Material-Animations in a terminal.
  3. 3Open the project. Open the cloned project in Android Studio and let it sync.
  4. 4Find the Fade and Slide examples. Look in res/transition for the XML transition files and in the activity Java files for the matching code.
  5. 5Run the activity transition example. Build and run the app on a device or emulator, then move between activities and press back to compare transitions.
  6. 6Run the shared element example. Tap the blue icon on the first screen to see the shared element transition to the second screen.
  7. 7Adapt the code. Copy the transition setup into your own activities, adjusting durations and transition names for your app.

What Material-Animations covers

The project shows three main uses of the Android Transition Framework: animating activity layout content when moving between activities, animating shared elements (Hero views) between activities, and animating view changes within one activity.

Each concept comes with short Java and XML code examples and screenshots.

  • Transitions between activities using Explode, Slide and Fade
  • Shared elements between activities
  • View changes within the same activity

Install Material-Animations by cloning and building it

The project is installed by cloning the repository and building it. The prerequisites listed for this project are Android Studio and Java.

Clone the repository with the command below, then open the project in Android Studio.

git clone https://github.com/lgvalle/Material-Animations

Create an activity transition with Fade or Slide

Transitions can be defined declaratively in XML files in res/transition, or programmatically in Java. The XML examples use fade and slide elements with a duration of 1000. In the declarative approach you inflate the transition with TransitionInflater; in the programmatic approach you create the object with new and call setDuration.

Set an exit transition on the activity you leave with setExitTransition, and an enter transition on the activity you open with setEnterTransition.

  • Activity A starts Activity B; the framework applies A's exit transition (slide in the example) to visible views.
  • The framework applies B's enter transition (fade in the example) to visible views.
  • On back press, the reverse animations run. If returnTransition and reenterTransition are defined, those are used instead.
Slide slide = new Slide(); slide.setDuration(1000); getWindow().setExitTransition(slide);

Define a return transition for a different back animation

If you do not define a return transition, Android runs a reversed version of the enter transition when going back. Defining a ReturnTransition lets you use a different animation when returning, for example a Slide out instead of a Fade out.

The project's ReturnTransition example sets a Fade as the enter transition and a Slide as the return transition on the same activity.

  • EnterTransition pairs with ReturnTransition
  • ExitTransition pairs with ReenterTransition
Fade fade = new Fade(); fade.setDuration(1000); getWindow().setEnterTransition(fade); Slide slide = new Slide(); slide.setDuration(1000); getWindow().setReturnTransition(slide);

Set up a shared element transition between activities

Shared element transitions link two separate views in two layouts with an animation. The view does not really move from one layout to the other; they are two independent views, and the framework creates an animation that gives the illusion of movement and shape change.

First, enable window content transitions in styles.xml by setting android:windowContentTransitions to true. Then give the origin and target views the same android:transitionName. They can have different ids and sizes, but the transition name must match. Finally, start the second activity with ActivityOptions.makeSceneTransitionAnimation().

  • Set android:windowContentTransitions to true in your app style
  • Use the same android:transitionName on both views
  • Pass the origin view and transition name to ActivityOptions.makeSceneTransitionAnimation()
ActivityOptions transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, sharedView, transitionName); startActivity(i, transitionActivityOptions.toBundle());

Check the project status before you build on it

The README marks the project as UNMAINTAINED. No maintenance is intended. The content is still valid as a reference, but it will not contain the latest new features.

Treat it as a learning reference for the Transition Framework rather than a source of current Android animation APIs. Shared element transitions with Fragments are mentioned at the end of the README, but this guide does not cover them.

What people use it for

  • Learning how Explode, Slide and Fade change the visibility of views during an activity change
  • Copying a Fade enter transition and Slide return transition into your own activity
  • Building a shared icon animation between a list screen and a detail screen
  • Using the project as a teaching example in an introduction to Android UI animation

Frequently asked questions

Is Material-Animations still maintained?

No. The README says the project is unmaintained and no maintenance is intended. The content is still valid as a reference, but it will not include the latest new features.

What do I need to run Material-Animations?

The listed prerequisites are Android Studio and Java. You clone the repository from GitHub and build it in Android Studio.

Is Material-Animations free to use?

The project is licensed under the MIT licence, as listed for this project. Check the repository's licence file for the full terms.

Can I use Material-Animations with Kotlin or non-Android projects?

The examples are specific to the Android framework and written in Java. They are not intended for non-Android developers.

What are the alternatives to Material-Animations?

Comparable resources are the Android Transition Framework documentation from Google and the Material Components for Android library. These are better choices if you need current APIs.

Why does my shared element transition not animate?

The README says both the origin and target views need the same android:transitionName, and android:windowContentTransitions must be set to true in your styles.xml. Check both of these first.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Material-Animations is a good free reference for Android developers and students who want copy-able Explode, Slide and Fade examples and a clear shared element walkthrough. It is unmaintained, so developers who need the latest Android animation APIs should use Google's Transition Framework documentation or Material Components for Android instead.

Install options & downloads