If, during onCreateView, you’re using the ‘new’ operator to instantiate a View instance (rather than inflating from XML, and/or using the attachToRoot parameter), your fragment’s View will be given default layout parameters of WRAP_CONTENT. If your content is smaller than the screen, this can look odd. Since you’re not directly adding the view to the view tree, it’s not immediately obvious how to correct this behavior.

Fortunately, it’s a simple fix – just use the setLayoutParams method, passing a LayoutParams object with MATCH_PARENT set to both dimensions.