Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show enter fragment above exit fragment while animating.

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.

like image 705
Dory Avatar asked Jan 09 '15 06:01

Dory


1 Answers

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

like image 60
CrazyOrr Avatar answered Nov 17 '22 04:11

CrazyOrr