Android Fragment does not respect match_parent as height

I had the same problem and think it happens when you inflate the layout in the Fragment’s onCreateView with null, like you did here:

mRootView = (ViewGroup) inflater.inflate(R.layout.list_content, null);

Instead you have to do this:

mRootView = (ViewGroup) inflater.inflate(R.layout.list_content,container, false);

Where container is the Viewgroup. At least, that solved the problem for me.


    <include layout="@layout/screen_main_fragment" />


I had to change layout_height=”wrap_content” to “match_parent”to make it work.

For some reason the FrameLayout does not get its layout from the XML.

I need to set it also in code (Fragment’s onCreateView):

mRootView = (ViewGroup) inflater.inflate(R.layout.list_content, null);
FrameLayout fl = (FrameLayout) mRootView.findViewById(;
fl.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
return mRootView;

Leave a Comment