YoKeyword / Fragmentation

[DEPRECATED] A powerful library that manage Fragment for Android
Apache License 2.0
9.73k stars 2.12k forks source link

求助大佬,我使用weixin的框架,mianActicity加载MainFragment,在MainFragment用loadMultipleRootFragment加载同级子fragment,使用showHideFragment切换fragment,但是会出现只有默认显示的那个子fragment有显示(会是残影吗?),其他的同级fragment没有内容,在有显示的那个fragment打开其他的fragment也是显示空白,如果我按home键把应用退到后台再返回,所有的fragment就能正常显示,求解(我的子fragment没有用懒加载会是这个原因吗?) #1238

Open captainhujian opened 4 years ago

captainhujian commented 4 years ago

Issues Guideline

Following information can help us to resolve the issue faster.

In addition, we do not accept issues unrelated to Fragmentation.

JantHsueh commented 4 years ago

建议对照demo检查一下代码,我在使用没有出现这样的问题。如果解决不了,把问题代码push上来,我帮你看看

captainhujian commented 4 years ago

MainActivity里的代码 @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (findFragment(MainFragment.class) == null) { loadRootFragment(R.id.main_container, MainFragment.newInstance(message)); }

}

MainFragment里的代码 @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Log.d(TAG, "onActivityCreated: "); SupportFragment firstFragment = findChildFragment(HomeFragment.class); if (firstFragment == null) { mFragments[FIRST] = HomeFragment.newInstance(); mFragments[SECOND] = RankingFragment.newInstance(); mFragments[THIRD] = DFragment.newInstance(); mFragments[FOURTH] = SortMainFragment.newInstance(); mFragments[FIVE] = ManageTabFragment.newInstance();

        loadMultipleRootFragment(R.id.fl_container, FIRST,
                mFragments[FIRST],
                mFragments[SECOND],
                mFragments[THIRD],
                mFragments[FOURTH],
                mFragments[FIVE]);
        mNavigationController.setSelect(SELECTED_FIRST);

    } else {
        // 这里库已经做了Fragment恢复,所有不需要额外的处理了, 不会出现重叠问题
        // 这里我们需要拿到mFragments的引用
        mFragments[FIRST] = firstFragment;
        mFragments[SECOND] = findChildFragment(RankingFragment.class);
        mFragments[THIRD] = findChildFragment(DFragment.class);
        mFragments[FOURTH] = findChildFragment(SortMainFragment.class);
        mFragments[FIVE] = findChildFragment(ManageTabFragment.class);
    }
}

用navigationController切换fragment mNavigationController = builder.build(); mNavigationController.addSimpleTabItemSelectedListener(new SimpleTabItemSelectedListener() { @Override public void onSelected(int index, int old) { showHideFragment(mFragments[index], mFragments[old]); } });

JantHsueh commented 4 years ago

你确定是这段代码的问题吗???我的意思是建议你把包含问题代码的项目,push到上来,我clone,帮你调试看看。

captainhujian commented 4 years ago

因为是工作上的代码,所以不方便push。大佬,我先在发现当我选择默认显示某个子fragment时才会出现这个问题(其他的界面不会),这个界面的网络请求较复杂一点,会不会是这个子项的问题