Open captainhujian opened 4 years ago
建议对照demo检查一下代码,我在使用没有出现这样的问题。如果解决不了,把问题代码push上来,我帮你看看
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]); } });
你确定是这段代码的问题吗???我的意思是建议你把包含问题代码的项目,push到上来,我clone,帮你调试看看。
因为是工作上的代码,所以不方便push。大佬,我先在发现当我选择默认显示某个子fragment时才会出现这个问题(其他的界面不会),这个界面的网络请求较复杂一点,会不会是这个子项的问题
Issues Guideline
Following information can help us to resolve the issue faster.
In addition, we do not accept issues unrelated to Fragmentation.