Hello, I am planning to make an educational game and I have encountered with kind of this task. For UI Layout, I want the child to dynamically scale (only width) with content inside. But default UI “Grid Layout” does not allow me to do such so( It requires all children to be in fixed width and height , which I do not want) .
I’ve thought a way of making with Multiple Horizontal Groups and Vertical Groups (with some calculation)
but those data are coming from backend API so, I have no control or what so ever.
I think you probably want to use the ContentSizeFitter component:
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/script-ContentSizeFitter.html
That handles size on a per-item basis. What type of layout you use beyond that is up to you.
But Grid Layout needs all children to be in the constant size, doesnt it? In this way, content size fitter cannot help me.
Grid does yes, but Horizontal layout and Vertical Layout don’t have this restriction.
The picture you show could probably be redone with:
-VertLayout
--HorizLayout1
---Item1
---Item2
---Item3
--HorizLayout2
---Item4
---Item5
---Item6
---Item7```
Size fitters would be on the items, and I suppose on the horiz layouts too, if they are varying heights.
I advise you work this up slowly, no code, just lay it out in the scene and understand how it has to be put together... it can be a little fiddly-widdly to get it right. :)