Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make second fragment overlap on first fragment while fragment transistion

I am working on fragment transition. When I replace the first fragment with the second fragment, it is appearing below the first fragment. I want it to move on top of first fragment. How can I do this?

fragmentTransaction.setCustomAnimations(animEnter, animExit, animPopEnter, animPopExit);
fragmentTransaction.replace(R.id.fragmentListView, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
like image 420
shekar Avatar asked Aug 30 '12 07:08

shekar


1 Answers

If you dont want to remove the first fragment you can use the add method instead and to place the 2nd on top of the 1st you need to reference the top most layout or use android.R.id.content

For example:

fragmentTransaction.setCustomAnimations(animEnter, animExit, animPopEnter, animPopExit);
fragmentTransaction.add(android.R.id.content, fragment,"MyStringIdentifierTag");
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();

This will add "fragment" on top of whatever is currently visible without removing the first fragment.

like image 77
Marco RS Avatar answered Nov 09 '22 12:11

Marco RS