简体   繁体   English

导航到另一个片段时,嵌套的 ViewPager 片段会冻结一秒钟

[英]Nested ViewPager fragment freezes for a second when navigating to another fragment

My viewPager has 5 fragments.我的 viewPager 有 5 个片段。 The first fragment itself contains viewPager for tabview (FOLLOWING and FOLLOWERS).第一个片段本身包含 tabview 的 viewPager(FOLLOWING 和 FOLLOWERS)。

在此处输入图像描述

second fragment should get data from the first, make API requests, and display results.第二个片段应该从第一个片段获取数据,发出 API 请求,并显示结果。 But before navigating to the second, it somehow moves to the "FOLLOWERS", waits for a second and only after this navigates to the second fragment.但在导航到第二个之前,它以某种方式移动到“FOLLOWERS”,等待一秒钟,然后才导航到第二个片段。 Does anyone know what is the reason for a such behavior?有谁知道这种行为的原因是什么?

ViewPager creates one fragment on each side of current tab by default.默认情况下, ViewPager在当前选项卡的每一侧创建一个片段。 When you move to the 2nd tab viewpager creates 3rd tab(3rd tab will be in an idle state).当您移动到第 2 个选项卡时,viewpager 会创建第 3 个选项卡(第 3 个选项卡将处于空闲状态)。 From viewpager documentation.来自 viewpager 文档。

int getOffscreenPageLimit () int getOffscreenPageLimit ()

Returns the number of pages that will be retained to either side of the current page in the view hierarchy in an idle state.返回将保留到空闲 state 中视图层次结构中当前页面任一侧的页面数。 Defaults to 1.默认为 1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM