Reputation: 1446
In my game, when the user presses the back button, it should bring up the pause menu (as a fragment). When the user presses the back button again, it should close the pause menu. All of this should be done with animations.
@Override
public void onBackPressed()
{
if (!paused)
{
// pause game here
if (mPauseFragment == null)
{
mPauseFragment = new PauseFragment();
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.fade_in, R.anim.fade_out, R.anim.fade_in, R.anim.fade_out);
ft.replace(R.id.pause_container, mPauseFragment, "pauseFragment");
// Start the animated transition.
ft.commit();
}
else
{
getSupportFragmentManager().beginTransaction().show(mPauseFragment).commit();
}
}
else
{
// resume game here
getSupportFragmentManager().beginTransaction().hide(mPauseFragment).commit();
}
paused = !paused;
}
It fades in just fine (but only once), but it doesn't fade out at all. Please give me a bit of hand, thanks.
Upvotes: 2
Views: 328
Reputation: 24235
ft.setCustomAnimations
gets applied to only that particular fragment transaction. Set your animation to every show hide transaction.
Upvotes: 1