Android FragmentPagerAdapter和FragmentStatePagerAdapter的区别

FragmentPagerAdapter官方解释:

This version of the pager is best for use when there are a handful of typically more static fragments to be paged through, such as a set of tabs. The fragment of each page the user visits will be kept in memory, though its view hierarchy may be destroyed when not visible. This can result in using a significant amount of memory since fragment instances can hold on to an arbitrary amount of state. For larger sets of pages, consider FragmentStatePagerAdapter.

意思大概就是:如果有少量的、常用的fragment,像tab标签页这样的,可以用FragmentPagerAdapter。划过的fragment,尽管视图不见了,但是会把他们保存在内存里,方便调用,因此这会占用大量的内存空间。

FragmentStatePagerAdapter官方解释:

This version of the pager is more useful when there are a large number of pages, working more like a list view. When pages are not visible to the user, their entire fragment may be destroyed, only keeping the saved state of that fragment. This allows the pager to hold on to much less memory associated with each visited page as compared to FragmentPagerAdapter at the cost of potentially more overhead when switching between pages.

意思就是说:如果有大量的fragment,或者fragment中有大量的数据(Bitmap)就用fragmentStatePagerAdater,它就像listview一样,当fragment不可见时候,仅仅保存fragment的状态,相对上面的而言,这会占用较少的内存。

posted @ 2015-05-15 10:17  brave-sailor  阅读(206)  评论(0编辑  收藏  举报