You could try adding a listener to the backstack: http://developer.android.com/reference/android/app/FragmentManager.html#addOnBackStackChangedListener(android.app.FragmentManager.OnBackStackChangedListener)
It will be called any time "something" is added or removed from/to the backstack.
You can then check the type of the class of the fragment (or maybe your holding the current fragment in a class - your Activity - variable) to decide if it's necessary to execute your animation.
The method in which you manage the layouts could simply check the visibility (getVisibility
) and if it's VISIBLE
then set to GONE
, if it's GONE
set to VISIBLE
.