使用Framelayout+Fragment+tab方式展示首页时,个别fragment有时会出现空白情况的解决

来源:互联网 发布:空手道自学软件 编辑:程序博客网 时间:2024/05/17 08:08

给领导演示应用的时候,某个fragment突然空白了,这就尴尬了

把fragment从v4包一个一个换成了sdk包下的,也不行,又重新过了一遍fragment的hide和show逻辑,没毛病。在生命周期方法里打了log,也正确调用了,但还是偶尔一片空白,是不是inflate layout文件有问题嘞?

以前的代码:

@Override    public View onCreateView(LayoutInflater inflater, ViewGroup container,                             Bundle savedInstanceState) {        if (null != rootView) {            ViewGroup parent = (ViewGroup) rootView.getParent();            if (parent != null) {                parent.removeView(rootView);            }        }elst{            rootView = loadView(inflater);        }        bindView(rootView);        return rootView;    }

改了之后的代码:

@Override    public View onCreateView(LayoutInflater inflater, ViewGroup container,                             Bundle savedInstanceState) {        if (null != rootView) {            ViewGroup parent = (ViewGroup) rootView.getParent();            if (parent != null) {                parent.removeView(rootView);            }        }        rootView = loadView(inflater);        bindView(rootView);        return rootView;    }

以前判断非空和加载布局文件是互斥的,非空就不加载了,所以偶尔会出问题。说明了一个问题,非空的时候可能没有加载完成。

0 0
原创粉丝点击