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的状态,相对上面的而言,这会占用较少的内存。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值