Search Unity

  1. Unity 2018.3 is now released.
    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. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    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:
    101
    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:
    517
    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:
    101
    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.