Slide Fragment from the Bottom in Android

Rohit Singh
Oct 31, 2020

--

If you want something like this.

Then you are at the right place. It’s really simple. Just Create these 4 anim XML files, and replace the current fragment with your new fragment.

2 Fragments - 4 Anims

  • DogsListFragment + DogDetailFragment
  • slide_in_bottom + slide_out_top + slide_in_top + slide_out_bottom.

But let’s visualize it first.

R.anim.slide_in_bottom

R.anim.slide_out_top

R.anim.slide_in_top

R.anim.slide_out_bottom

And this code for sliding in the fragment from the bottom.

How to reverse this on the back button click?

If you want to reverse the animation on the back button click? just pop the current fragment from the backstack.

getSupportFragmentManager().popBackStack();

Using this approach you can make similar animations like left to right, right to left, etc.

Full code sample

Putting up content takes a lot of time and effort 😓.
👏 clap 👏 If you think you learned something from this article. Also follow me on Medium. It motivates me write more frequently. You can find me on Stackoverflow,Github,and,on Linkedin.
Give feedback and feel free to correct mistakes.

Read More:

What is addToBackStack in Fragment

--

--

Rohit Singh
Rohit Singh

Written by Rohit Singh

Android Developer | Arizona State University | NASA Psyche Research Aide

Responses (1)