I am trying to achieve the following effect using FragmentTransaction.setCustomAnimations.
I added an elevation to the fragment that slides in from the bottom of 30sp and it worked.
I have tried many solutions suggested here. Here are the full code and output that combines all the idea + adding elevation.
Without elevation:
With elevation:
Add an elevation to the root
----
----
How to slide in the fragment from the bottom?
getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(R.anim.slide_in_bottom, R.anim.do_nothing, R.anim.do_nothing, R.anim.slide_out_bottom)
.replace(R.id.fragmentContainer, currentFragment, "TAG")
.addToBackStack("TAG")
.commit();
How to do the reverse when the back button is pressed?
getSupportFragmentManager()
.popBackStack();
Since we have already defined enter and exit animation on
setCustomAnimations()
method. CallingpopBackStack();
takes care of the reverse animation.
R.anim.slide_in_bottom
R.anim.slide_out_bottom
R.anim.do_nothing