在ViewPager preLOAD片段的看法首次运行首次、片段、看法、ViewPager

2023-09-06 23:07:06 作者:抹不掉的轻狂

我用ViewPager持有3个片段,每个片段加载列表。问题是,当该应用程序运行的第一次,我刷到下一个片段,该片段需要一段时间来加载(约2秒)之前,其观点是可见的。这是一个非常怪异的行为。我想要的是,一旦应用程序已经启动,在ViewPager所有片段应准备好用户,所以当他们通过片段刷卡,没有等待时间。我该怎么办呢?

I'm using ViewPager that holds 3 fragments, each fragment loads a list. The problem is when the application runs for the first time and I swipe to the next fragment, this fragment needs sometime to load (about 2 seconds) before its view is visible. This is a very weird behavior. All I want is once the app has started, all fragments in ViewPager should be ready for user so when they swipe through fragments, there's no wait time. How can I do that?

推荐答案

还是叫setOffscreenPageLimit()在的onCreate()(初始化ViewPager后)。所述OffscreenPageLimit设置的应保留到当前页面的任一侧(在情况2)的页数。有了这一切的片段都将实例化。

Just call setOffscreenPageLimit() in onCreate() (after initializing ViewPager). The OffscreenPageLimit sets the number of pages that should be retained to either side of the current page (in your case 2). With this all of your fragments will be instantiate.

(安等(强烈推荐)可能是增加你的列表或listadapters的性能,因为不健全的2秒的加载时间也不好)

(An other (highly recommended) possibility is to increase the performance of your lists or listadapters, because a loading time of 2 seconds doesn't sound good)

 
精彩推荐
图片推荐