我正在使用bottomnavigationbar和这个交换片段。但是,动画只有在同一片段的第二次显示之后才开始工作。如果您不明白,请观看以下视频:https://drive.google.com/file/d/1aeao_-wg2k17smvpbrhu3ujla4iai6dq/view?usp=sharing
oncreate():
fm = getSupportFragmentManager().beginTransaction();
fm.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
fm.add(R.id.gen_fr, settings).hide(settings);
fm.add(R.id.gen_fr, events).hide(events);
fm.add(R.id.gen_fr, refs).hide(refs);
fm.add(R.id.gen_fr, earn);
fm.commit();
切换片段时:
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
fm = getSupportFragmentManager().beginTransaction();
fm.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
switch (item.getItemId()) {
case R.id.main_room:
if (active != earn) {
fm.hide(active).show(earn);
active = earn;
}
break;
case R.id.refs_room:
if (active != refs) {
fm.hide(active).show(refs);
active = refs;
}
break;
case R.id.events_room:
if (active != events) {
fm.hide(active).show(events);
active = events;
}
break;
case R.id.settings_room:
if (active != settings) {
fm.hide(active).show(settings);
active = settings;
}
break;
}
fm.commit();
return true;
暂无答案!
目前还没有任何答案,快来回答吧!