I found this tutorial on how to build an expandable "accordion"-style UI element, but it doesn't seem to deal well with dynamic resizing. If I put a Vertical Layout Group inside the collapsible body, then add elements into the Vertical Layout Group at runtime, it squishes those elements down rather than expanding to accommodate them.
Just to complicate matters further, the expandable UI element is itself inside of a Vertical Layout Group, which is inside of a Scroll Box. Because I have a Scroll Box, I should be able to expand the view indefinitely, without being constrained by the height of the screen, and just scroll up and down as needed, but no matter how I tinker with the settings, I can't make that happen.
This seems like it ought to be very simple--it is very simple in every other UI framework I've worked with--but for the life of me I can't make it work in Unity. How do I get this to work? Specifically:
- At the top level, I have a Scroll Box element. Its height should dynamically resize to accommodate everything inside of it.
- Inside the Scroll Box's viewport is a Rect Transform with a Vertical Layout Group attached. Its height should dynamically resize to accommodate everything inside of it, and none of the layout elements inside of it should force any element to be smaller than its "natural" vertical size.
- Inside one of the layout elements in the Vertical Layout Group is a collapsible UI element. Its body contains another Vertical Layout Group. When expanded, its body element's height should dynamically resize to accommodate everything inside of it.
Is there any way to do that?