[2017.1] How to layout 2 objects, 1 fixed width and 1 flexible?

I hope this is a simple question - this was easy in Unity 4.6 but the layout system seems to have changed so much I can’t figure out how to do it any more.

Suppose I want to divide the screen into 2 “panels”, one fixed at 300 units wide, the other with flexible width to take up the rest of the screen; previously I would:

  • Create a HorizontalLayoutGroup the size of the screen.

  • Disable “Force Expand Child Width”.

  • Add Child #1 with LayoutElement set to “Preferred Width = 300”

  • Add Child #2 with LayoutElement set to “Flexible Width = 1”

I appreciate that I could forgo the layout group and simply use anchors/offsets, but with the setup above you could adjust the width on Child #1 and #2 will automatically readjust to fill whatever space is remaining, plus I could apply this to more complex layouts where simply positioning each element individually is much too inflexible to be useful.

What further complicates the issue, as pointed out in this thread is that layout groups now contain a “Child Controls Size” option, which doesn’t appear in the documentation. Does the documentation fail to accurately reflect what’s in the editor often?

If anyone has an understanding of the current UI components, or can demonstrate how to achieve what I’m aiming for in this example, I would greatly appreciate the help!

1 Like

Bump