使用viewpager切换fragment时,发现如果超过2个页面切换,切换第三个页面时会重新创建。
这样使用fragment没有任何意义。
查看API文档,只需要设置缓存页面数即可。
mPager.setOffscreenPageLimit(3);
http://www.android-doc.com/reference/android/support/v4/view/ViewPager.html
void |
setOffscreenPageLimit(int limit)
Set the number of pages that should be retained to either side of the current page in the view hierarchy in an idle state.
|