Reputation: 63
I need to change the expanding direction of the VerticalLayoutGroup. With the default behavior the group will expand downstairs. What i want is, that the group will expand upstairs.
The expected behavior is described in this Video. (Link to the answer on stackoverflow https://stackoverflow.com/a/43192904/11236801)
The solution on the link is, to rotate the LayoutGroup about 180°. Now this seems more like a workaround, because all childs have to be rotated as well. The solution suggested by this one will not give the expected behavior shown in the video.
I added the ContentSizeFitter to the LayoutGroup like described in this link in the Unity Answers. Now the LayoutGroup will expand in both directions (upstairs and downstairs).
Is there any solution to accomplish the desired behavior without rotating the LayoutGroup?
Edit: I also noticed a downside from the rotating approach: The Billboard Script from the MixedRealityToolkit will force the LayoutGroup to rotate back to 0°.
Upvotes: 6
Views: 10138
Reputation: 113
Set the Y pivot to 1, you will see that the panel will start growing to the bottom instead of both sizes simultaneously
Upvotes: 0
Reputation: 11
Old question but the accepted answer makes it more complicated than necessary: the desired direction of expansion can be controlled via the sign of Spacing
in the VerticalLayoutGroup
.
Upvotes: 1
Reputation: 4870
This works for me:
Note the Child Alignment setting on the Vertical Layout Group
, and the Pivot settings on the Rect Transform
. This makes the layout group expand upwards when more items are added.
Also note the presence of a Content Size Fitter
component, and its Vertical Fit set to Preferred Size, that will adjust the height of the layout group when content is added or removed.
Upvotes: 19