0

I'm trying to replace a fragment from a container with another fragment. for this I use this code:

 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.setCustomAnimations(R.anim.open_next, R.anim.close_next, R.anim.open_main, R.anim.close_next);
    transaction.replace(R.id.frag_container, new Activity_SendTrack(), "newFragment");
    transaction.addToBackStack("Activity_Fragment2");
    transaction.commit();

Everything goes perfectly with one exception, the incoming fragment is animated below the outgoing fragment. I want the new incoming fragment to be displayed above the outgoing fragment. how can i solve the problem?

Nick
  • 49
  • 4

1 Answers1

0

I finally managed to find the following solution

        Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.frag_container);
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.setCustomAnimations(R.anim.open_next, R.anim.close_main, R.anim.open_main, R.anim.close_next);
        transaction.add(R.id.frag_container, new Activity_SendTrack(), "newFragment");
        if (currentFragment != null) {
            transaction.hide(currentFragment);
        }
        transaction.addToBackStack("Activity_Fragment");
        transaction.commit();
Nick
  • 49
  • 4