Fragment ReenterTransition does not work. Need help explaining the various transitions of the Fragment

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) { // Setup the new fragment and transaction Fragment newFragment = FragmentFactory.newFragment(fragId, args); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(containerId, newFragment, tag); fragmentTransaction.addToBackStack(tag); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && transitionViews != null) { // Add the shared elements for (int i = 0; i < transitionViews.size(); i++) { final Pair pair = transitionViews.get(i); fragmentTransaction.addSharedElement((View) pair.first, (String) pair.second); } // Setup the transitions Transition transitionMove = TransitionInflater.from(this).inflateTransition(android.R.transition.move); Transition transitionFade = TransitionInflater.from(this).inflateTransition(android.R.transition.fade); // transitionFade.setDuration(500); // Slow down the transition to help see what happening // Apply the relevant transitions to each fragment newFragment.setSharedElementEnterTransition(transitionMove); newFragment.setEnterTransition(transitionFade); newFragment.setExitTransition(transitionFade); mCurrentFragment.setExitTransition(transitionFade); mCurrentFragment.setReenterTransition(transitionFade); mCurrentFragment.setSharedElementReturnTransition(transitionMove); } fragmentTransaction.commit(); } 
  • 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?

+6
android
Jul 08 '15 at 4:14
source share

No one has answered this question yet.

See similar questions:

16
How to delay snippet transition in Android Lollipop?

or similar:

twenty
Failback does not work correctly when using shared fragment sections
17
Enter a passage for a fragment with a common element that the common element is intended
17
transition with a common element works with FragmentTransaction.replace (), but does not work with FragmentTransaction.add ()
fourteen
Android Fragment Animation onResume
four
Custom Fragment Transition Animation Doesn't Work Right When I Click BackStack
3
The transition from the common element does not work in the fragment on the back
one
Need help with common elements Fragment transitions
0
Transition a common item from a RecyclerView to a fragment
0
Text attenuation using Transition Manager not working with RecyclerView
0
Common Item Transitions - Fragments



All Articles