docs.unity.cn
    Show / Hide Table of Contents

    Class LayoutElement

    Inheritance
    Object
    Object
    Component
    Behaviour
    MonoBehaviour
    UIBehaviour
    LayoutElement
    Inherited Members
    UIBehaviour.Awake()
    UIBehaviour.Start()
    UIBehaviour.OnDestroy()
    UIBehaviour.IsActive()
    UIBehaviour.OnRectTransformDimensionsChange()
    UIBehaviour.OnCanvasGroupChanged()
    UIBehaviour.OnCanvasHierarchyChanged()
    UIBehaviour.IsDestroyed()
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(String, Single)
    MonoBehaviour.InvokeRepeating(String, Single, Single)
    MonoBehaviour.CancelInvoke(String)
    MonoBehaviour.IsInvoking(String)
    MonoBehaviour.StartCoroutine(String)
    MonoBehaviour.StartCoroutine(String, Object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StartCoroutine_Auto(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(String)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(Object)
    MonoBehaviour.useGUILayout
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.TryGetComponent(Type, Component)
    Component.TryGetComponent<T>(T)
    Component.GetComponent(String)
    Component.GetComponentInChildren(Type, Boolean)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(Boolean)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, Boolean)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(Boolean)
    Component.GetComponentsInChildren<T>(Boolean, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type, Boolean)
    Component.GetComponentInParent(Type)
    UnityEngine.Component.GetComponentInParent<T>(System.Boolean)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, Boolean)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(Boolean)
    Component.GetComponentsInParent<T>(Boolean, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.CompareTag(String)
    Component.SendMessageUpwards(String, Object, SendMessageOptions)
    Component.SendMessageUpwards(String, Object)
    Component.SendMessageUpwards(String)
    Component.SendMessageUpwards(String, SendMessageOptions)
    Component.SendMessage(String, Object)
    Component.SendMessage(String)
    Component.SendMessage(String, Object, SendMessageOptions)
    Component.SendMessage(String, SendMessageOptions)
    Component.BroadcastMessage(String, Object, SendMessageOptions)
    Component.BroadcastMessage(String, Object)
    Component.BroadcastMessage(String)
    Component.BroadcastMessage(String, SendMessageOptions)
    Component.transform
    Component.gameObject
    Component.tag
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(Object)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, Boolean)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, Boolean)
    Object.Destroy(Object, Single)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, Boolean)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.FindObjectsOfType(Type, Boolean)
    Object.FindObjectsByType(Type, FindObjectsSortMode)
    Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, Single)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    UnityEngine.Object.FindObjectsByType<T>(UnityEngine.FindObjectsSortMode)
    UnityEngine.Object.FindObjectsOfType<T>(System.Boolean)
    UnityEngine.Object.FindObjectsByType<T>(UnityEngine.FindObjectsInactive, UnityEngine.FindObjectsSortMode)
    Object.FindObjectOfType<T>()
    UnityEngine.Object.FindObjectOfType<T>(System.Boolean)
    UnityEngine.Object.FindFirstObjectByType<T>()
    UnityEngine.Object.FindAnyObjectByType<T>()
    UnityEngine.Object.FindFirstObjectByType<T>(UnityEngine.FindObjectsInactive)
    UnityEngine.Object.FindAnyObjectByType<T>(UnityEngine.FindObjectsInactive)
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.FindFirstObjectByType(Type)
    Object.FindAnyObjectByType(Type)
    Object.FindObjectOfType(Type, Boolean)
    Object.FindFirstObjectByType(Type, FindObjectsInactive)
    Object.FindAnyObjectByType(Type, FindObjectsInactive)
    Object.ToString()
    Object.name
    Object.hideFlags
    Namespace: UnityEngine.UI
    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
    Single
    Implements
    ILayoutElement.flexibleHeight

    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
    Single
    Implements
    ILayoutElement.flexibleWidth

    ignoreLayout

    Should this RectTransform be ignored by the layout system?

    Declaration
    public virtual bool ignoreLayout { get; set; }
    Property Value
    Type Description
    Boolean
    Implements
    ILayoutIgnorer.ignoreLayout
    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
    Int32
    Implements
    ILayoutElement.layoutPriority

    minHeight

    The minimum height this layout element may be allocated.

    Declaration
    public virtual float minHeight { get; set; }
    Property Value
    Type Description
    Single
    Implements
    ILayoutElement.minHeight
    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
    Single
    Implements
    ILayoutElement.minWidth
    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
    Single
    Implements
    ILayoutElement.preferredHeight
    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
    Single
    Implements
    ILayoutElement.preferredWidth
    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()

    Declaration
    public virtual void CalculateLayoutInputHorizontal()
    Implements
    ILayoutElement.CalculateLayoutInputHorizontal()

    CalculateLayoutInputVertical()

    Declaration
    public virtual void CalculateLayoutInputVertical()
    Implements
    ILayoutElement.CalculateLayoutInputVertical()

    OnBeforeTransformParentChanged()

    Declaration
    protected override void OnBeforeTransformParentChanged()
    Overrides
    UIBehaviour.OnBeforeTransformParentChanged()

    OnDidApplyAnimationProperties()

    Declaration
    protected override void OnDidApplyAnimationProperties()
    Overrides
    UIBehaviour.OnDidApplyAnimationProperties()

    OnDisable()

    Declaration
    protected override void OnDisable()
    Overrides
    UIBehaviour.OnDisable()

    OnEnable()

    Declaration
    protected override void OnEnable()
    Overrides
    UIBehaviour.OnEnable()

    OnTransformParentChanged()

    Declaration
    protected override void OnTransformParentChanged()
    Overrides
    UIBehaviour.OnTransformParentChanged()

    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.

    Extension Methods

    UIBehaviourExtensions.InvokeOnEnable(UIBehaviour)
    UIBehaviourExtensions.InvokeOnDisable(UIBehaviour)
    UIBehaviourExtensions.InvokeAwake(UIBehaviour)
    UIBehaviourExtensions.InvokeRebuild(UIBehaviour, CanvasUpdate)
    UIBehaviourExtensions.InvokeLateUpdate(UIBehaviour)
    UIBehaviourExtensions.InvokeUpdate(UIBehaviour)
    UIBehaviourExtensions.InvokeOnRectTransformDimensionsChange(UIBehaviour)
    UIBehaviourExtensions.InvokeOnCanvasGroupChanged(UIBehaviour)
    UIBehaviourExtensions.InvokeOnDidApplyAnimationProperties(UIBehaviour)
    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on 12 June 2023