The thing I'm trying to achieve should be quite simple but I can't manage to find the solution to my problem.
I have fragment A. When fragment A's button is clicked, fragment B is displayed:
@Override
public void onClick(View v) {
Fragment fragment = new PostMeasurementFragment();
FragmentTransaction fragmentTransaction = ((PostActivity)context).getSupportFragmentManager().beginTransaction();
fragmentTransaction.addToBackStack(null);
fragmentTransaction.add(R.id.post_container, fragment, "PostMeasurementFragment");
fragmentTransaction.commit();
}
Fragment B has a transparent background so I'd like fragment A to be visible behind fragment B. If I use .replace rather than .add, I can see only fragment B and that's make sense because fragment A was removed by the .replace method. When I use .add I can't see fragment B though and I know it's there because of .addToBackStack: I need to click the back button twice to get rid of fragment A, which makes me thing the first click is quitting fragment B which I can't see.
Given that, I believe fragment B is being added behind (or below, if you think of it as a pile) of fragment A. Is there a way to bring it to front?
Inflate Fragment B into a view in the layout of Fragment A (such as a FrameLayout) where the height that view is set to wrap_content
, and the Fragment's view will fill whatever size necessary. Use add()
when building the FragmentTransaction.