Search Unity

Question Spacing objects in Horizontal Layout or Grid Layout

Discussion in 'UGUI & TextMesh Pro' started by grappler, Jan 25, 2023.

  1. grappler

    grappler

    Joined:
    Jun 26, 2015
    Posts:
    13
    I'm trying to get images within a Horizontal Layout (or Grid Layout) to appear closer together. I have spacing set to 0 and I've tried adding left and right padding, but I can't find a way to make this simple adjustment. The alignment is fine, I just want less space between them. When I add padding it doesn't squash them together as I'd expect.

    I'm scaling the images to get them the right size, is this affecting the spacing? I mean is the spacing being determined by the original size? Any help would be appreciated.
     
  2. Deleted User

    Deleted User

    Guest

    Have you tried toggling on the 'Control Child Size' options?

    For example:

    If you create a horizontal layout group, the default settings will have 'Child Force Expand' set to both Width and Height ON.

    Now toggle on the Width in the 'Control Child Size' options. It will stretch out the child objects to fit the width of the parents rect transform. Now you can add the spacing you want.

    As for the grid layout group, the spacing is the 'X' (width) and 'Y' (height)
     
  3. grappler

    grappler

    Joined:
    Jun 26, 2015
    Posts:
    13
    Thank you! Grid Layout would just wrap to the next row, but I got it working for Horizontal Layout Group.

    Control Child Size (off for both X and Y), Use Child Scale (on for both), Child Force Expand (on for both). This sized them appropriately and the Spacing field now works as expected.
     
    Deleted User likes this.