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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With