Class LayoutElement
Inherited Members
Namespace: UnityEngine.UI
Assembly: UnityEngine.UI.dll
Syntax
[AddComponentMenu("Layout/Layout Element", 140)]
[RequireComponent(typeof(RectTransform))]
[ExecuteAlways]
public class LayoutElement : UIBehaviour, ILayoutElement, ILayoutIgnorer
Constructors
LayoutElement()
Declaration
protected LayoutElement()
Properties
flexibleHeight
The extra relative height this layout element should be allocated if there is additional available space.
Declaration
public virtual float flexibleHeight { get; set; }
Property Value
Type | Description |
---|---|
float |
flexibleWidth
The extra relative width this layout element should be allocated if there is additional available space.
Declaration
public virtual float flexibleWidth { get; set; }
Property Value
Type | Description |
---|---|
float |
ignoreLayout
Should this RectTransform be ignored by the layout system?
Declaration
public virtual bool ignoreLayout { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Setting this property to true will make a parent layout group component not consider this RectTransform part of the group. The RectTransform can then be manually positioned despite being a child GameObject of a layout group.
layoutPriority
The Priority of layout this element has.
Declaration
public virtual int layoutPriority { get; set; }
Property Value
Type | Description |
---|---|
int |
minHeight
The minimum height this layout element may be allocated.
Declaration
public virtual float minHeight { get; set; }
Property Value
Type | Description |
---|---|
float |
Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when using UI elements.
public class ExampleClass : MonoBehaviour
{
public Transform MyContentPanel;
//Sets the flexible height on on all children in the content panel.
public void Start()
{
//Assign all the children of the content panel to an array.
LayoutElement[] myLayoutElements = MyContentPanel.GetComponentsInChildren<LayoutElement>();
//For each child in the array change its LayoutElement's minimum height size to 64.
foreach (LayoutElement element in myLayoutElements)
{
element.minHeight = 64f;
}
}
}
minWidth
The minimum width this layout element may be allocated.
Declaration
public virtual float minWidth { get; set; }
Property Value
Type | Description |
---|---|
float |
Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when using UI elements.
public class ExampleClass : MonoBehaviour
{
public Transform MyContentPanel;
//Sets the flexible height on on all children in the content panel.
public void Start()
{
//Assign all the children of the content panel to an array.
LayoutElement[] myLayoutElements = MyContentPanel.GetComponentsInChildren<LayoutElement>();
//For each child in the array change its LayoutElement's minimum width size to 200.
foreach (LayoutElement element in myLayoutElements)
{
element.minWidth = 200f;
}
}
}
preferredHeight
The preferred height this layout element should be allocated if there is sufficient space.
Declaration
public virtual float preferredHeight { get; set; }
Property Value
Type | Description |
---|---|
float |
Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when using UI elements.
public class ExampleClass : MonoBehaviour
{
public Transform MyContentPanel;
//Sets the flexible height on on all children in the content panel.
public void Start()
{
//Assign all the children of the content panel to an array.
LayoutElement[] myLayoutElements = MyContentPanel.GetComponentsInChildren<LayoutElement>();
//For each child in the array change its LayoutElement's preferred height size to 100.
foreach (LayoutElement element in myLayoutElements)
{
element.preferredHeight = 100f;
}
}
}
preferredWidth
The preferred width this layout element should be allocated if there is sufficient space. The preferredWidth can be set to -1 to remove the size.
Declaration
public virtual float preferredWidth { get; set; }
Property Value
Type | Description |
---|---|
float |
Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when using UI elements.
public class ExampleClass : MonoBehaviour
{
public Transform MyContentPanel;
//Sets the flexible height on on all children in the content panel.
public void Start()
{
//Assign all the children of the content panel to an array.
LayoutElement[] myLayoutElements = MyContentPanel.GetComponentsInChildren<LayoutElement>();
//For each child in the array change its LayoutElement's preferred width size to 250.
foreach (LayoutElement element in myLayoutElements)
{
element.preferredWidth = 250f;
}
}
}
Methods
CalculateLayoutInputHorizontal()
After this method is invoked, layout horizontal input properties should return up-to-date values. Children will already have up-to-date layout horizontal inputs when this methods is called.
Declaration
public virtual void CalculateLayoutInputHorizontal()
CalculateLayoutInputVertical()
After this method is invoked, layout vertical input properties should return up-to-date values. Children will already have up-to-date layout vertical inputs when this methods is called.
Declaration
public virtual void CalculateLayoutInputVertical()
OnBeforeTransformParentChanged()
Declaration
protected override void OnBeforeTransformParentChanged()
Overrides
OnDidApplyAnimationProperties()
Declaration
protected override void OnDidApplyAnimationProperties()
Overrides
OnDisable()
Declaration
protected override void OnDisable()
Overrides
OnEnable()
Declaration
protected override void OnEnable()
Overrides
OnTransformParentChanged()
Declaration
protected override void OnTransformParentChanged()
Overrides
OnValidate()
Declaration
protected override void OnValidate()
Overrides
SetDirty()
Mark the LayoutElement as dirty.
Declaration
protected void SetDirty()
Remarks
This will make the auto layout system process this element on the next layout pass. This method should be called by the LayoutElement whenever a change is made that potentially affects the layout.