When configuring the layout with code, force the view to update its layout immediately with layoutIfNeeded() before adding buttons to the container.