3

I have 2 Fragment's - A and B. In order to switch from Fragment A to Fragment B I'm using this function:

public static void swapFragments(FragmentManager fragmentManager, int containerViewId, Fragment newFragment)    {

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.add(containerViewId, newFragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
}

Let's say Fragment A takes the entire screen's area and Fragment B takes only the upper half of the screen.

The problem: When switching to Fragment B, the user is still able to see Fragment A at the lower half of the screen...

How can I hide Fragment A when switching to Fragment B ?

p.s: I don't want to use replace instead of add in the swap function above - I don't want Fragment A's onCreate() to be called each time the user navigate back from Fragment B to Fragment A...

Thanks in advance.

ofirbt
  • 1,846
  • 7
  • 26
  • 41

2 Answers2

0

Could you maybe move Fragment A? E.g. slide it down when Fragment B appears? Simply move it outside the screen. Something like what's discussed in this question

Community
  • 1
  • 1
Jonas Kalderstam
  • 1,136
  • 12
  • 27
0

Well, without any other option, I've just took care that Fragment B will occupy the entire screen so that Fragment A can't be seen.

More adjustments should have n=been done due to Android's bugs, such as: Google's stupid bug

ofirbt
  • 1,846
  • 7
  • 26
  • 41