- Home /
Make Scroll View size fitting to children size in one dimension
This is a part of my current hierarchy:
Scroll View
Viewport
Content
Button_1
Button_2
Button_3
Scrollbar Vertical
Content
has a Vertical Layout Group
and a Content Size Fitter
, so all buttons are below each other and their size also defines the size of Content
. Now I want the Viewport
and Scroll View
width to also be fitting to the Content
but the height of course not, so that the buttons are scrollable in the top-bottom direction and perfectly fitting in the left-right direction.
I already tried adding a Content Size Fitter
to Scroll View
and Viewport
but as soon as I set the Horizontal Fit
to Preferred Size
the width very small.
What is the correct way to do this? Thanks in advance!
The issue with adding a size fitter to scrollview and viewport is that this is not how it's supposed to be set up. Scroll View can be any size, Viewport is the "window" you want your scrollables to live and be constrained to, and Content is the block that gets moved around.
If you have your viewport the same size as your content window, then there is no scrolling, as all items are already displayed.
If you want them to fit horizontally, it's best to just set the width of view port manually, since there are often funky results when parenting multiple content fits on top of one another.
If you have your viewport the same size as your content window, then there is no scrolling, as all items are already displayed.
The horizontal dimension should be the same and only in the vertical scrolling should be possible. So there is no contradiction.
If you want them to fit horizontally, it's best to just set the width of view port manually, since there are often funky results when parenting multiple content fits on top of one another.
Possible, but then I have to update this manually every time I change something in one of the lower layers, for example increasing the size of a Button to fit an image.