• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
5
Question by benjaminvancaspel · Jan 16, 2018 at 04:59 AM · 2duilayouthorizontalvertical

How to lock element width or height in a vertical or horizontal layout?

I want to achieve the following for a group of buttons within a horizontal layout group but have been completely confused by the documentation that is provided:

alt text

I want to be able to lock one item, lock one element or limit the max width of an item whilst the others are flexible or free to resize their width. I believe that this would work the same with all of the layout scripts, Horizontal Layout, Vertical Layout and Grid Layout

buttonlayout.png (8.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
17
Best Answer

Answer by benjaminvancaspel · Jan 16, 2018 at 05:14 AM

Rather unintuitively this is how it actually works.

You need to first make sure that your GameObject with the Horizontal Layout Group applied has Child Controls Size checked for "Width" and "Height". You then need to have Child Force Expand "Width" = unchecked, "Height" = checked.

Locked Item: Needs a Layout Element script added to it.
- Preferred width: set to the value you want.
- Flexible Width: 0 (if it's left at 1, it'll just be flexible with 100 added to it and yes you have to check a box for "flexible" when you want it to not be flexible)

Flexible Item: Needs a Layout Element script added to it.
- Flexible Width: 1

If you leave the Flexible Width off, it will just collapse the button's width.

The results are consistent once you get the hang of it, but the problem is bending your head to click on all the different settings with names that don't fit to get the right numbers.

Be careful if you're going to use this for a Vertical group to set Child Force Expand "Width=checked" and "Height=unchecked" on the layout group

alt text


layoutlocked.png (59.4 kB)
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Massan · Nov 22, 2019 at 08:46 PM 0
Share

Life Saver! Thanks!

avatar image vonSchlank · Oct 14, 2020 at 01:49 PM 0
Share

Eternal life and forever free beer for you, my friend!

avatar image Splendidus · Oct 28, 2020 at 10:46 AM 0
Share

Why isn't this in the official tutorial? Great explanation, thank you!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

188 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I make Horizontal Layout Group starts from right to left? 4 Answers

Make movement vertically,How to move Vertically? 1 Answer

Cannot set pivot for children of horizontal layout. 0 Answers

Simple way to fit rotated UI element to parent 2 Answers

Vertically Stationary Camera for 2D? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges