Recursive Penguin

Android Fragment layout

Fragment correct

I recently ran into a problem when using a FragmentTranscation to replace a LinearLayout with a Fragment. The Fragment that I was putting into the layout was not filling the view port properly. Luckily it was a fairly easy problem to fix.

FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
trans.replace(, mFragment);

The code above was creating a layout that had an intermediary FrameLayout that did not have the proper layout parameters. NoSaveStateFrameLayout was set to wrap content so the children were not filling the viewport.

Broken layout

Luckily the fix was just to change the code in onCreateView of the Fragment:


View layout = inflater.inflate(R.layout.fragment_page_edit, null);


View layout = inflater.inflate(R.layout.fragment_page_edit, container, false);