The transition animation between fragments occurs after reopening the fragment

Viewed 31

I am using BottomNavigationBar and switch fragments with this. However, animations start to work only after the second showing of the same fragment. If you do not understand what, watch this video: 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();

When switching fragments:

 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;
0 Answers
Related