Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to change the height of a Panel?

Discussion in 'UGUI & TextMesh Pro' started by DigitalAdam, Oct 14, 2015.

  1. DigitalAdam

    DigitalAdam

    Joined:
    Jul 18, 2007
    Posts:
    1,192
    I have a Panel with a Vertical Layout Group assigned, and I would only like it to change the height based on the amount of content with, not stretch. How do I do that?

    Thanks.
     
  2. DigitalAdam

    DigitalAdam

    Joined:
    Jul 18, 2007
    Posts:
    1,192
    Here is an example. I would like to have a fixed height for each of the Panels that have the text/slider. Right now it seems to stretch the height of the Background panel.
     

    Attached Files:

    • ss.png
      ss.png
      File size:
      18 KB
      Views:
      903
  3. DWilliams

    DWilliams

    Joined:
    Jan 12, 2015
    Posts:
    63
    You can give each child that exists in the Vertical Layout Group its own Layout Element and give a specific preferred height to that element. You can also add a Content Size Fitter to the same object as the Vertical Layout Group and set the vertical fit to use preferred size. That should allow you to add as many or as few child elements to the vertical layout group as you wish and that object will always get vertically sized according to how many children it has with each child maintaining its own preferred height.
     
  4. DigitalAdam

    DigitalAdam

    Joined:
    Jul 18, 2007
    Posts:
    1,192
    That worked out great, thanks. One more question if you don't mind... how do I get the gray Panel in my screenshot to align to the top of my black panel instead of the center? I want to keep the height of the black panel fixed, but I would like everything else within to align to the top.
     

    Attached Files:

    • ss2.jpg
      ss2.jpg
      File size:
      87.6 KB
      Views:
      815