Search Unity

Question Expanding width of items on a table when vertical scrollbar inactive

Discussion in 'UGUI & TextMesh Pro' started by lakired, Mar 21, 2023.

  1. lakired

    lakired

    Joined:
    Sep 10, 2021
    Posts:
    3
    Hi! I have an issue that's probably easily resolvable for someone with more experience, but I've tried searching for a solution myself and have come up empty handed.

    I have a Scroll View with a vertical scroll bar on the right hand side. For its content, I have a prefab GameObject with a horizontal layout group and two children (one button, one TMP Text), which is added in (or later hidden) via code. The result is a scrollable list of items, with two elements side by side creating a small table. All of this works fine except I can't get the rightside element (the text box) to expand to fill in the empty space when there are too few elements to require a scrollbar (or conversely, to shrink when the scrollbar is active if I increase its width). This is purely an aesthetic issue, but it's really annoying me that I can't figure out how to do it. Thanks!
     
  2. orloKun

    orloKun

    Joined:
    Jan 9, 2016
    Posts:
    7
    Hi lakired. Does the scrollview content object have a layout group component (horizontal or vertical)? With those components you can choose to force childrens to expand either vertically or horizontally depending on your need. Also, a content size fitter would also be needed to keep the content flexible to your list of objects.
     
  3. lakired

    lakired

    Joined:
    Sep 10, 2021
    Posts:
    3
    Yes, it has both a vertical layout component and a content size fitter on the content object. None of the force settings work to get the contents to expand into the space vacated by the scrollbar.
     
  4. orloKun

    orloKun

    Joined:
    Jan 9, 2016
    Posts:
    7
    Can you show a picture of your setup (Hierarchy and Inspector)? Do the child objects have any component that might be resizing it?