Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between enter/exit and popEnter/popExit animations?

In setCustomAnimations() it takes four resource id for the animation. Not really understand them. If someone having clearer picture of it it would be appreciated if you could explain.

Let's say having fragment A add in the place holder and backstack.

FragmentTransaction ft = fm.beginTransaction();         ft.replace(R.id.holder, fragA, FragmentA.FRAGMENT_NAME);         ft.addToBackStack(FragmentA.FRAGMENT_NAME);         ft.setCustomAnimations(R.anim.slide_in_from_bottom, R.anim.slide_in_from_top, R.anim.slide_in_from_left, R.anim.slide_in_from_right);         ft.show(frag);         ft.commit(); 

And the replace with fragment B:

FragmentTransaction ft = fm.beginTransaction();         ft.replace(R.id.holder, fragB, FragmentB.FRAGMENT_NAME);         ft.addToBackStack(FragmentB.FRAGMENT_NAME);         ft.setCustomAnimations(R.anim.slide_in_from_bottom, R.anim.slide_in_from_top, R.anim.slide_in_from_left, R.anim.slide_in_from_right);         ft.show(frag);         ft.commit(); 

next time if do a popstack()

fm.popBackStackImmediate(FragmentB.FRAGMENT_NAME,                                 FragmentManager.POP_BACK_STACK_INCLUSIVE); 

Which transaction's animation it will be running from?

/**  * Set specific animation resources to run for the fragments that are  * entering and exiting in this transaction. The <code>popEnter</code>  * and <code>popExit</code> animations will be played for enter/exit  * operations specifically when popping the back stack.  */ public abstract FragmentTransaction setCustomAnimations(@AnimRes int enter,         @AnimRes int exit, @AnimRes int popEnter, @AnimRes int popExit); 
like image 380
lannyf Avatar asked Nov 30 '16 01:11

lannyf


People also ask

What is popEnterAnim?

The enterAnim and exitAnim is applied when navigating to or from the destination the "regular way", while popEnterAnim is applied to the destination when it is shown as a result of the destination "above" it being popped from the backstack.

How do you animate a fragment?

To animate the transition between fragments, or to animate the process of showing or hiding a fragment you use the Fragment Manager to create a Fragment Transaction . Within each Fragment Transaction you can specify in and out animations that will be used for show and hide respectively (or both when replace is used).

How do you animate fragment transitions?

At a high level, here's how to make a fragment transition with shared elements: Assign a unique transition name to each shared element view. Add shared element views and transition names to the FragmentTransaction . Set a shared element transition animation.


1 Answers

Let's start simple case:

Replace Fragment A with Fragment B (your second code snippet)

  • Fragment B runs enter animation
  • Fragment A runs exit animation

Press back button and undo the replace operation

  • Fragment B runs popExit animation
  • Fragment A runs popEnter animation

Now to answer your question.

You don't say if the container already has a fragment or not. Let's consider both cases:

  1. Container already had a fragment (let's call it Fragment 0) when the first operation to replace with Fragment A was called. When popping the entire stack:

    • Fragment B runs popExit animation (set in second snippet)
    • Fragment 0 runs popEnter animation (set in first snippet)
  2. Container was empty so replacing with Fragment A was essentially an add operation. When popping entire stack:

    • Fragment B runs popExit animation (set in second snippet)
    • No popEnter animation runs since container is now empty
like image 140
kris larson Avatar answered Oct 04 '22 04:10

kris larson