Search Unity

[Layout Groups] How do I prevent them from overriding size of children?

Discussion in 'UGUI & TextMesh Pro' started by SweetBro, Aug 22, 2014.

  1. SweetBro

    SweetBro

    Joined:
    Jan 14, 2013
    Posts:
    69
    I have a horizontal layout group, I don't want it to stretch it's children, only automatically place them horizontally one after another. Any suggestions on how to go about that?
     
  2. secondbreakfast

    secondbreakfast

    Joined:
    Jan 5, 2013
    Posts:
    98
    My first guess would be to try and set the stretch settings on the anchor for each child. Look at the example demo in the sticky thread. I has one scene where there are OK and Cancel buttons that are right justified using that layout.
     
  3. SweetBro

    SweetBro

    Joined:
    Jan 14, 2013
    Posts:
    69
    Right so after finding the Ok/Cancel buttons you referred too and poking around a bit I figured it out.

    So in addition to having a layoutgroup, you also need to add the Layout Element component which has some values you can adjust. Changing Flexible Width/Height to 0, will allow you to give every element in the group a fixed height/width using min/preferred height/width.

    EDIT: Actually I lied, this only changes they dimensions of the actual layout not the content within. Still gonna continue searching for a solution

    EDIT2: Okay, so what you actually have to do is instead of adding Layout Element to the group, you actually have to add it to the individual elements within the group.
     
    Last edited: Aug 22, 2014
    Miso99, DDeathlonger, levlaj and 3 others like this.
  4. WallHackJack

    WallHackJack

    Joined:
    Feb 6, 2016
    Posts:
    2
    Thank you sweet boy... but boy oh boy did I have a tough time finding this one.

    Adding some key words here for SEO.

    Layout group prevents child resize
    Can't resize child of layout group
    Layout group child size locked
     
    Miso99 and DDeathlonger like this.