How are transaction between two fragment in BottomNavigationView in Apps like YouTube so smooth?

时间:2018-10-02 09:16:28

标签: android android-fragments bottomnavigationview

I am making an application that has MainActivity that contains BottomNavigationView and FrameLayout above it. There are 3 Fragments say Fragment A, B, and C.

My doubt is, How do I make switching of Fragments as quick as YouTube Android application? By saying quick, I mean that, when I am on "Home" tab of Youtube application and I switch to the "Trending" tab and again go back to the "Home" tab, it simply loads "Home" tab within fraction of seconds, as if it just hided the inflated page in background and showed up when selected from BottomNavigationView. And also, It inflates the page exactly to the same position where I left.

When I am trying to implement the same in my Application, the RecyclerView in Fragment A re-inflates if I come back from Fragment B.

I am expecting the idea how they do it and in which method they do it (For eg. onStart or onDestroy or onViewCreated)...

1 个答案:

答案 0 :(得分:0)

如果您使用的是viewpager,则增加viewpager的偏移量限制

viewpager.OffscreenPageLimit = 2;

Tt的限制默认为1。我希望这可以解决您的问题。 谢谢