zoukankan      html  css  js  c++  java
  • FragmentActivity+FragmentTabHost+Fragement instead of TabActibvity+TabHost+Activity

    http://www.tuicool.com/articles/NzeMJz

    http://www.tuicool.com/articles/FJ7VBb

    FragmentTabHost切换Fragment时避免UI重新加载


    不过,初次实现时发现有个缺陷,每次FragmentTabHost切换fragment时会调用onCreateView()重绘UI。

    解决方法,在fragment onCreateView 里缓存View:

    Java代码 收藏代码
    private View rootView;// 缓存Fragment view

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState)
    {
    Log.i(TAG, "onCreateView");

    if (rootView == null)
    {
    rootView = inflater.inflate(R.layout.fragment_1, null);
    }
    // 缓存的rootView需要判断是否已经被加过parent,如果有parent需要从parent删除,要不然会发生这个rootview已经有parent的错误。
    ViewGroup parent = (ViewGroup) rootView.getParent();
    if (parent != null)
    {
    parent.removeView(rootView);
    }
    return rootView;
    }

  • 相关阅读:
    oracle 失效对象自动重新编译
    Apache commons 工具集简介
    正则表达式 元字符
    LayUI之弹出层
    Js和JQuery基础
    单点登录
    java算法题
    SpringBoot自定义注解
    SpringBoot基础
    java面试题
  • 原文地址:https://www.cnblogs.com/ZacharyHodgeZou/p/3953720.html
Copyright © 2011-2022 走看看