0
\$\begingroup\$

I have a content size fitter on the content within the scroll view. However the content size fitter is over double the height needed and when scolling there is a large blank space at the bottom on the content that keeps scrolling.

I have tried to change all the settings but nothing has made it shrink and fit the content.

enter image description here enter image description here enter image description here

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Although I don't have enough information to determine whether this is the problem you're facing, I'll just add it as an answer for you (and other people with similar problems) to check if this actually causes it.

Unlike what you might expect, the Content size fitter does not set its own size to the size of its child components. it sets its size to its layout properties. These layout properties are set by layout components such as layout groups (which might set layout properties based on childs values) or LayoutElement. You can see these properties in the same place where the preview window is displayed for Materials etc.

enter image description here

As shown in the image, check what is modifying this preferred size of 'Content', make sure it is the GridLayoutGroup, if something else is, then that's the problem. Also check if these values are what you expect them to be. (In your example with 28 items, size of 195 and given padding of 10 I expect it to be either 1375 or 1960)

Also note that the 'H Delta' display in the inspector only updates properly in playmode. Outside of playmode it often shows incorrect values when driven by a content size fitter, which might hide the actual problem for us.

Also note when debugging that h delta is not the height in pixels, to get it to display height in pixels, set the anchor min Y to 1 aswell. (just make sure Y min and max are equal, the actual value doesn't matter for this)

\$\endgroup\$
4
  • \$\begingroup\$ thank you. Great explanation. My Preferred Height is set to Image. Not sure how to change these settings \$\endgroup\$ Commented Oct 3, 2019 at 21:12
  • \$\begingroup\$ If I disable the Image then it will fit the buttons correctly. The image is the background grid. However the image is actually the correct size of the buttons so it shouldn't cause the content size to be larger \$\endgroup\$ Commented Oct 3, 2019 at 21:19
  • \$\begingroup\$ What is this correct size? In most cases texture sizes will be bigger then displayed to support multiple display resolutions. An image of 2048x2048 is fairly common to have. But most screens have a display resolution of 1920x1080 or smaller, meaning that if textures are not resized, most screens can't display them fully without resizing. There are multiple ways to get this to work how you want though. And I'm pretty sure I don't know all of them. Options I know about: alter the 'Pixels per Unit' in the sprite settings, use a tiling background or give each button its own background \$\endgroup\$
    – troien
    Commented Oct 4, 2019 at 8:55
  • 1
    \$\begingroup\$ The simple solution at this point is to move the image component to be the first child of Content, and add a LayoutComponent to it that has Ignore Layout checked. \$\endgroup\$
    – Ed Marty
    Commented Oct 4, 2019 at 12:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .