片段之间的转换动画在重新打开片段后发生

j9per5c4  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(167)

我正在使用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;

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题