Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Android Transitions

Android Transitions

An exploration of the Transitions framework for animating the transition between two screens

Bryan Herbst

December 11, 2014
Tweet

More Decks by Bryan Herbst

Other Decks in Programming

Transcript

  1. Transitions
    Bryan Herbst
    Senior Software Engineer
    The Nerdery

    View Slide

  2. What is a Transition?
     Easy way to animate a group of Views
     Animates from one Scene to another Scene
     Can be used to animate between Activities and Fragments

    View Slide

  3. Scenes
     Snapshot of a ViewGroup
     Can be defined in Java or XML (or let the framework do it)

    View Slide

  4. Making a transition

    View Slide

  5. Making a transition (old)
    ObjectAnimator anim = ObjectAnimator.ofFloat(mButton, "alpha", 1f, 0f);
    anim.start();

    View Slide

  6. Making a transition (new)
    TransitionManager.beginDelayedTransition(mRoot, new Fade());
    mButton.setVisibility(View.INVISIBLE);

    View Slide

  7. AutoTransition
     Fade
     Move
     Resize

    View Slide

  8. How it works
    1. beginDelayedTransition() => Take a snapshot of ViewGroup
    2. Update Views
    3. On next layout pass, Android takes another snapshot and creates animations
    Note: you can also define Scenes in XML

    View Slide

  9. Activity Transitions

    View Slide

  10. Activity Transitions (API 21)
     Request Window.FEATURE_ACTIVITY_TRANSITIONS and
    Window.FEATURE_CONTENT_TRANSITIONS in both Activities
     Set a transition name on the View in both Activities
     Create a Bundle with
     Call startActivity(intent, transitionBundle);
    makeSceneTransitionAnimation(activity, sharedView, viewTransitionName).toBundle();

    View Slide