Skip to content

Instantly share code, notes, and snippets.

@bherbst
Last active October 29, 2015 18:14
Show Gist options
  • Save bherbst/3b5998026a5154d30cdf to your computer and use it in GitHub Desktop.
Save bherbst/3b5998026a5154d30cdf to your computer and use it in GitHub Desktop.
Animated fragment transition
DetailsFragment details = DetailsFragment.newInstance();
// Note that we need the API version check here because the actual transition classes (e.g. Fade)
// are not in the support library and are only available in API 21+. The methods we are calling on the Fragment
// ARE available in the support library (though they don't do anything on API < 21)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
details.setSharedElementEnterTransition(new DetailsTransition());
details.setEnterTransition(new Fade());
setExitTransition(new Fade());
details.setSharedElementReturnTransition(new DetailsTransition());
}
getActivity().getSupportFragmentManager()
.beginTransaction()
.addSharedElement(holder.image, "sharedImage")
.replace(R.id.container, details)
.addToBackStack(null)
.commit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment