android fragment 重复创建的问题

时间:2014-09-24 20:13:29   收藏:0   阅读:514

解决fragment重复创建目前用到有两个方法:

1、fragment同viewpager一起使用:

vp.setOffscreenPageLimit(3);//设置缓存页面的个数


2、fragment单独使用:

onCreateView()方法中加入:

 if (null == view) {

  view = inflater.inflate(R.layout.XXX, null);

}

ViewGroup parent = (ViewGroup)view.getParent();
        if (parent != null) {
            parent.removeView(view);
        }
        return view;


还其他方法:

使用fragment的进程管理,不过感觉比较麻烦。

原文:http://blog.csdn.net/xulei881/article/details/39527885

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!