Fragment in TabLayout only load when user slide Android

前端 未结 2 1571
旧巷少年郎
旧巷少年郎 2021-01-05 07:06

Hi I\'m making an app with A fragment and few child fragment inside it using tablayout and viewpager. The problem is all

2条回答
  •  清歌不尽
    2021-01-05 07:52

    The Viewpager by default loads the adjacent fragment to ensure make the app smooth, so that when the user swipe to the fragments (already loaded) it is there. To change is default behavior, use viewpager.setOffscreenPageLimit(int limit) where limit is how many fragment next to the one you are on will be preloaded. Hope this helps

提交回复
热议问题