Last active
October 29, 2015 18:14
-
-
Save bherbst/3b5998026a5154d30cdf to your computer and use it in GitHub Desktop.
Animated fragment transition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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