Skip to content

Instantly share code, notes, and snippets.

@Tanapruk
Created July 20, 2017 03:24
Show Gist options
  • Save Tanapruk/a3f47d44783567bcebd367ca918db543 to your computer and use it in GitHub Desktop.
Save Tanapruk/a3f47d44783567bcebd367ca918db543 to your computer and use it in GitHub Desktop.
Android Transition

SharedElementTransition between Transition

When you open another activity and want to have a small picture (a view) inside a button animate to a big profile picture. That picture is called shared element.

  • Create a Scene that holds view and transitionName. Pack them inside Bundle and send it to another Activity. The destination view's xml must have android:transitionName attribute.

Origin

Intent intent = new Intent(context, AnotherActivity.class);
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(context, Pair.create(originView, "btnTransition"));
startActivity(intent, optionsCompat.toBundle());

Destination

<...
android:transitionName="btnTransition"

.../>

Simple Animation

You can animate things without much hassles by doing this.

  • Call TransitionManager.beginDelayedTransition() before setting visibility.

Simpliest

TransitionManager.beginDelayedTransition(layouptContainerViewGroup);
view.setVisibility(View.GONE);

Add Some Bounce Effects

 TransitionSet set = new TransitionSet();
 set.setOrdering(TransitionSet.ORDERING_SEQUENTIAL)
        .addTransition(new Fade(Fade.OUT))
        .addTransition(new ChangeBounds().setInterpolator(new BounceInterpolator()))
        .addTransition(new Fade(Fade.IN));
TransitionManager.beginDelayedTransition(layoutContainerViewGroup, set);
        
view.setVisibility(View.GONE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment