I am implementing an animation of the transition of fragments between elements in a RecyclerView, and the fragment shows the details of the clicked element. In other words, relatively common ...
"Click on the map in the list and it will expand to a detailed view until the rest of the list disappears"
... kind of thing.
Moving from a RecyclerView to a detailed view works fine. The common elements of the element go into a new state, while the rest of the RecyclerView elements disappear.
However, when the BackStack is unloaded, the transition of the common elements back to their previous state, but other RecyclerView elements do not disappear. They appear instantly at the beginning of the animation, as you can see in this on- screen video.
Activity processes quite a lot of fragments, so I do the transaction in the following generalized method:
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public void setFragment(int fragId, Bundle args, List<Pair> transitionViews, String tag, int containerId) {
- I tried to play by enabling / disabling transition switching to Enter / Return.
- I tried playing with various transition setting methods for fragments.
- I read a lot of blogs and SO questions on this topic.
I found a http://www.androiddesignpatterns.com/2014/12/activity-fragment-transitions-in-android-lollipop-part1.html blog on this subject, and the brockoli sample code is very useful, but could not solve the problem.
Perhaps this is a problem with my understanding of why each transition is needed?
This is how I understand it.
My mCurrentFragment and newFragment have 5 different transition configurators:
setSharedElementEnterTransition Sets the transition to be used for common elements passed to the content scene.setSharedElementReturnTransition Sets the transition that will be used for common elements passed back during the pop output of the back stack .setEnterTransition Sets the transition that will be used to move the views to the source scene.setExitTransition Sets the transition that will be used to move objects from the scene when the fragment is deleted, hidden or detached when it does not push the back stack .setReenterTransition Sets the transition that will be used to move Views into the scene upon return due to the appearance of the back stack .
When my setFragment method is setFragment , the animation plays from mCurrentFragment to newFragment with the following properties:
newFragment SharedElementEnterTransition defines how common elements will transition to newFragment .
(In my case, the click on the CardView element expands and one of the TextView that it contains moves)newFragment EnterTransition defines how the rest of the newFragment child views, which are not shared elements , will go to the screen.
(In my case, the ToolBar disappears at the bottom of the screen. In fact, the ToolBar disappears behind the exiting RecyclerView. Is there a way to change it so that it is in front?)mCurrentFragment ExitTransition defines how mCurrentFragment child views, which are not shared elements , will be disconnected from the screen.
(In my case, mCurrentFragment only contains a RecyclerView, so the effect is that the rest of the RecyclerView elements disappear in the background)
When BackStack is called, I expect the following:
- The SharedElementReturnTransition for
mCurrentFragment determines how shared items will go back to mCurrentFragment .
(In my case, the CardView contract goes back to the size of the RecyclerView element, and the TextView that it contains moves backward). - The ExitTransition for
newFragment defines how the child views of newFragment , which are not shared elements , move from the screen.
(In my case, the bottom toolbar disappears) - The ReenterTransition for
mCurrentFragment defines how the remaining child views of mCurrentFragment , which are not shared elements , are returned back to the screen.
(In my case, other RecyclerView elements should disappear, but this does not happen, they are instantly visible behind transitional shared elements).
I didn’t understand something?