Lesson 3
Layouts and constraints
Goal: Arrange items automatically and stop them stretching.
about 6 min3 practice exercises
Placing ten shop cards by hand is slow and breaks when you add an eleventh. A layout arranges siblings for you.
Add a UIListLayout to a frame and its children line up in a row or a column:
FillDirectionchooses row or column.Paddingis the gap between items.- Order comes from each item's
LayoutOrder(or its name). - For a strict grid of equal cells, use UIGridLayout instead.
A layout takes over. It overrides the Position of the items it manages, so setting their position yourself no longer does what you expect.
Constraints stop UI stretching badly across screens. Each one is added as a child of the object it limits:
| Constraint | Keeps |
|---|---|
| UIAspectRatioConstraint | A fixed width-to-height ratio, for example square cards |
| UISizeConstraint | Size between a minimum and a maximum |
| UITextSizeConstraint | Text between a minimum and maximum size |
With TextScaled on, text grows and shrinks with its box, and a UITextSizeConstraint keeps it readable. Roblox advises against a minimum text size below 9.
Go deeper on Rodex
Sources
Checked against Roblox's documentation on . The lesson is in our own words; these pages are the source of truth.