美文网首页
Fragment add和replace的区别

Fragment add和replace的区别

作者: Hong2018 | 来源:发表于2017-02-20 15:45 被阅读0次

FragmentTransaction add 和 replace 区别

参考博文

###add


Add a fragment to the activity state. This fragment may optionally also have its view (if Fragment.onCreateView returns non-null) into a container view of the activity.


覆盖原fragment, 添加入一个新fragment后, 原来的fragment仍然存活

###replace


Replace an existing fragment that was added to a container. This is essentially the same as calling remove(Fragment) for all currently added fragments that were added with the same containerViewId and then add(int, Fragment, String) with the same arguments given here.


replace 是先remove掉相同id的所有fragment,然后在add当前的这个fragment

从性能出发, 推荐使用replace

相关文章

网友评论

      本文标题:Fragment add和replace的区别

      本文链接:https://www.haomeiwen.com/subject/fcrewttx.html