Unity layout controls

1. Basic properties of automatic layout components

insert image description here

Attributes: Function:
Padding The padding inside the edges of the layout group.
Spacing Spacing between layout elements.
Child Alignment The alignment to use for child layout elements if they do not fill the available space.
Control Child Size Whether the layout group controls the width and height of its child layout elements.
Use Child Scale Whether the layout group considers the scale of its child layout elements when sizing and laying out elements.
Child Force Expand Whether to force child layout elements to expand to fill the extra available space.

Let's combine it with the scene to see the effect:
Child Alignment: The alignment of the child object relative to the parent object (if these elements do not fill the available space)
insert image description here
insert image description here
insert image description here

Child Force Expand Whether to force child layout elements to expand to fill the extra available space.
When this property is set, the space of the parent object will be equally divided by the number of layout elements, and the layout of each child element will start from the equal space.
insert image description here
insert image description here
Control Child Size Whether the layout group controls the width and height of its child layout elements.
This attribute is used to control the length and width of layout sub-elements, withChild Force ExpandAttributes used together
1. When not controlling
insert image description here
2. Control width
insert image description here
3. Control height
insert image description here
4. Control width and height
insert image description here

2. Layout Element component

insert image description here

Note:
mustMate layout controlsUse, it can only act on the objects managed by the layout control
If the corresponding direction layout control is checkedChild Force ExpandThen Min, Preferred, and Flexible will all be affected,MinOn the basis of setting the minimum value of the child element first, the remaining layout space will be divided equally.PreferredIf it is less than the value after the element divides the layout space equally, the value set by Preferred has no effect, and ==Flexible== fills the layout space proportionally will not work

Attributes: Function:
Ignore Layout When enabled, this layout element will not be affected by the layout system.
Min Width The minimum width this layout element should have.
Min Height The minimum height this layout element should have.
Preferred Width The preferred width this layout element should have before allocating additional available width,Priority is lower than Min Width.
Preferred Height The preferred height this layout element should have before allocating additional available height,Priority is lower than Min Height.
Flexible Width The relative amount of additional available width this layout element should fill relative to its siblings.fill proportionally
Flexible Height The relative amount of additional available height this layout element should fill relative to its siblings,Fill proportionally.
Layout Priority The layout priority of this component. If a game object has more than one component that contains layout properties (for example, an Image component and a LayoutElement component), the layout system will use the property value from the component with the highest Layout Priority value. If those components have the same Layout Priority value, the layout system will use the maximum value of each property, regardless of which component that property came from.

insert image description here
Set the minimum width of the first child element to 300
insert image description here
insert image description here

3.Aspect Ratio Fitter (aspect ratio adapter)

insert image description here

Attributes: Function:
Aspect Mode How to resize the rectangle to enforce the aspect ratio.
None Don't fit the rectangle to the aspect ratio.
Width Controls Height Automatically adjust height based on width.
Height Controls Width Automatically adjust width according to height.
Fit In Parent Automatically adjusts width, height, position, and anchor points so that the rectangle fits the parent's rectangle while maintaining the aspect ratio. There may be some space in the parent rectangle that will not be covered by this rectangle (take the smaller value of the length and width of the parent object).
Envelope Parent Automatically adjusts width, height, position, and anchor points so that the rectangle covers the entire area of ​​the parent while maintaining the aspect ratio. This rectangle may extend wider than the parent rectangle (take the larger value of the parent object's length and width).
Aspect Ratio The aspect ratio to enforce. This is the ratio of width divided by height.

4.Content Size Fitter (content size adapter)

insert image description here

Attributes: Function:
Horizontal Fit How to control the width.
Unconstrained Does not stretch width based on layout elements.
Min Size Stretches the width based on the minimum width of the layout element.
Preferred Size Stretches the width according to the preferred width of the layout element.
Vertical Fit How to control altitude.
Unconstrained Does not stretch height based on layout elements.
Min Size Stretches the height based on the minimum height of the layout element.
Preferred Size Stretches the height according to the preferred height of the layout element.

Guess you like

Origin blog.csdn.net/weixin_45136016/article/details/126003954
Recommended