6

Effect what I want to achieve is to overlay enter (new) fragment above the exit(old) fragment, but when I am replacing old fragment by new fragment,the old one just vanishes and new fragment slides up the container, which is visible (container).

I don't want to animate the old fragment, just keeping old fragment as it is and while it is visible slide up the new fragment above it.

Below is my code :

// First time adding fragment i.e. "oldFragemnt"
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, oldFragment, "oldFragemnt");
ft.addToBackStack(null);
ft.commit();

// while adding "newFragemnt"
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.new_slide_in_up,0,0,R.anim.new_slide_out_down);                                   
ft.replace(R.id.content_frame, newFragment, "newFragemnt");
ft.addToBackStack(null);
ft.commit();

Guide me where I am going wrong. My old fragment is vanishing while the new fragment is sliding up.

Dory
  • 7,462
  • 7
  • 33
  • 55
  • 1
    Do you want like [this](http://trickyandroid.com/fragments-translate-animation/) ? – SweetWisher ツ Jan 09 '15 at 07:42
  • You have to add the both fragmnet not replace as the name itself tells that it is replacing that's why your old fragment is removing. – Surender Kumar Mar 02 '15 at 06:28
  • https://stackoverflow.com/questions/13005961/fragmenttransaction-animation-to-slide-in-over-top This is the right solution! – wudizhuo Aug 11 '20 at 07:28
  • https://stackoverflow.com/questions/13005961/fragmenttransaction-animation-to-slide-in-over-top This solution is works for me. – wudizhuo Aug 11 '20 at 07:30

2 Answers2

1

You can try to replace the replace() with add() to achieve the effect you want. Hope this will help you.

CrazyOrr
  • 307
  • 2
  • 3
  • 13
0

The new fragment should have an enter animation like this(which you might be doing already): enter.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >

<translate
    android:duration="400"
    android:fromXDelta="90%"
    android:fromYDelta="0%"
    android:toXDelta="0%"
    android:toYDelta="0%"
    android:zAdjustment="top" />

The old fragment should stay in the same place like hold. hold.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >

<translate
    android:duration="400"
    android:zAdjustment="bottom" />

Vansi
  • 777
  • 2
  • 11
  • 23