Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Unity UI Layout Group: Position elements at opposite sides

Discussion in 'Unity UI & TextMesh Pro' started by SimRuJ, Oct 12, 2018.

  1. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    85
    I've got this panel with a layout group, a "previous" and a "next" button:



    Bigger version: click

    Is it possible to position the "previous" button at the very left and the "next" button on the very right using the layout group?
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    486
    Is there a reason that you need the layout group at all, rather than just using anchors? If you remove the layout group and just anchor each button to a different side of the parent, that would be simpler and more efficient.

    Even if you're going to have other objects that you want the layout group to arrange in the remaining space, you might want to make the layout group into a child that only takes up the space between the side buttons, or give the side buttons LayoutElement components with "ignore layout" checked so that they won't be controlled by the layout group (and then give the layout group enough padding on the left and right so that it won't overlap the buttons).

    But if there's some reason that you still need these buttons to be controlled by the layout group, you'll probably need to insert a third object between the buttons to take up the extra space. I think you'll want to turn off "child force expand", turn on "child controls size", and add a LayoutElement to each child, with a preferred width for the buttons and a flexible width for the center piece that takes up the slack.
     
    SimRuJ likes this.
  3. SimRuJ

    SimRuJ

    Joined:
    Apr 7, 2016
    Posts:
    85
    Thanks for your answer!
    To be honest, I was just wondering if it was even possible because I like layout groups but I'm not a fan of setting fixed lengths for obvious reasons.
    I've solved it with anchors now, thanks.