Markos Evlogimenos
Markos Evlogimenos

Reputation: 718

Need the old fragment on top, when using backstack

Main screen has fragment A.

Clicking replaces fragment A with fragment B.

Pressing the back button replaces fragment B with A.

However until the full animation is completed fragment B is on top of fragment A.

I want them the other way around.

The obvious code:

                    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
                    fragmentTransaction.setCustomAnimations(R.anim.slide_in_down, R.anim.custom_out, R.anim.custom_in, 0);
                    fragmentTransaction.replace(R.id.content, fragment, "contentFragment").addToBackStack(null).commit();

The effect i'm trying to achieve:

Imagine fragment A is a door.

The door opens (fragment A exit animation) and fragment B falls in the screen (fragment B enter animation)

When you press the back button, fragment B remains as is and the door (fragment A) closes on top of it (fragment a enter animation)

Anyone knows how to do this in a clean way, without adding another fragment A when the back button is pressed?

Upvotes: 1

Views: 33

Answers (1)

Markos Evlogimenos
Markos Evlogimenos

Reputation: 718

So far the best way was to have 2 fragment containers one on top of the other. I keep fragment A in top container and fragment B in other one and in 1 transaction i do remove / add on the 2 different containers.

Upvotes: 1

Related Questions