2

I have a fragment replace transaction setup like so:

CreateGestureFragment frag = new CreateGestureFragment(number, name, type);
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.setCustomAnimations(R.animator.zoom_enter, R.animator.anim_stay, R.animator.anim_stay, R.animator.zoom_exit);
    transaction.replace(R.id.fragment_container, frag);
    transaction.addToBackStack(null);
    transaction.commit();

And my zoom_enter is like so:

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together" >
<objectAnimator
    android:propertyName="scaleX"
    android:valueFrom="0.5"
    android:valueTo="1.0"
    android:duration="@android:integer/config_mediumAnimTime">
</objectAnimator>

<objectAnimator 
    android:propertyName="scaleY"
    android:valueFrom="0.5"
    android:valueTo="1.0"
    android:duration="@android:integer/config_mediumAnimTime">        
</objectAnimator>

The anim_stay is just a placeholder, there is no actual animation for it (i just set scaleX from 1.0 to 1.0). The intended behavior for replacing fragment A with fragment B is: Fragment B enters while zooming in on top of fragment A, and when popping back, fragment B exits while zooming out and reveals the fragment A from before.

However it seems that when replacing, fragment A's animation happens on top of fragment B's animation, thus the animation will be missed until the animation is completed and fragment B is shown entirely. The question is, how do I layer the animation of fragment B's zoom enter on top of fragment A such that I can see the actual animation?

I tried setting the animation of fragment A to simply 0, however in this case, although I can see the zoom enter of fragment B, fragment A simply disappears at the start of the animation which is not what I want.

Jason Hu
  • 1,237
  • 2
  • 15
  • 29
  • so you say that fragment A which is below fragment B, when animating is shown on top of fragment B? – pskink Jan 08 '15 at 19:07
  • For the replacement of fragment A to fragment B, the animation of fragment A is on top of fragment B (which is not what I want, I want B to be shown on top of A). For popping the back stack of fragment B back to fragment A, the animation for fragment B is shown on top of fragment A, which is fine in this case. Thus the animation corresponding to the "exiting" fragment is always shown on top of "entering" fragment. – Jason Hu Jan 08 '15 at 19:10
  • Currently looking into a similar question: http://stackoverflow.com/questions/13005961/fragmenttransaction-animation-to-slide-in-over-top?rq=1 – Jason Hu Jan 09 '15 at 00:47
  • you can try to replace "transaction.replace" with "transaction.add" but you will loose A's exit animation – pskink Jan 09 '15 at 09:11

0 Answers0