Search Unity

  1. Unity 2019.1 beta is now available.
    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. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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:
    125
    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:
    556
    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:
    125
    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.