Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make frames fit in scrolling frames with scale?

I'm trying to make a scrolling frame that automatically sizes itself so the items inside fit but the items inside get bigger. I know the problem but I don't know how to fix it, does anyone else know what to do? Here's my code if it helps:

grid:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
	local absoluteContentSize = grid.AbsoluteContentSize

	scrollingFrame.CanvasSize = UDim2.fromOffset(0, absoluteContentSize.Y)
	scrollingFrame.CanvasPosition = Vector2.new(0, absoluteContentSize.Y)
end)

1 answer

That's because your elements have size by Scale so everytime you resize the frame, the children gets resized and then the frame again gets resized because of that and then again.

UIAspectRatioConstraint is what you need, you need to select Ratio, if Ration is 1 then it's parent will always be a square, no matter what. You need to select ratio that you need for example Ratio 8 would make the parent frame look like long sausage but Ratio 0.25 would make it look like wide sausage.

You need to clone the UIAspectRatio and put it into all the frames inside the scroll frame.

UIAspectRatio

14 comments

0

I tried this but it doesn't fix anything for me it just spaces out the frames again

0

oohh waait, why are you setting CanvasPosition? Just set the CanvasSize, remove line 5. Make sure to not remove the UIAspectRatio tho, without it nothing will work

0

It's the canvas size that stretches my frames though :/

0

The canvas position doesn't affect anything but the position the canvas is at.

0

so what's happening to the items inside, they are spacing out or they are getting bigger? or both? UIAspectRatio prevents them from being bigger so that should not be a problem, so are they then spacing out? how exactly does that look?

0

With the aspect ratio inside of the frames the frames then space out.

0

Also I'm using scale.

0

can you make a picture of how exactly does the 'spacing out' look?

0

No, but the longer the canvas size on the Y the more the frames space out on the Y

0

Space out in your case is that they have huge gaps or they are too big on Y? I don't know exactly what space out is sry. If they are stretched then you can only use UIAspectRatio to fix that, it will prevent them from stretching. You can change other properties of the AspectRatio to fit with your frame.

0

The padding needs to be lower but I don't know how to do that.

0

aha i got you, it has to do something with the UIAspectRatio. Basically you need to adjust grid size in UIGridLayout to fix that, it's very bad i know, you can also switch to offset size grid if it's that bad.

0

The problem is that AspectRatio forces the size while UIGridLayout does not want that so they create this, just a little lowering size of GridLayout X or Y (Just randomly playing with it) might help in this situation. - Offset size might be the best, it will look bigger for smaller phones which is good for them but might cause bad left or right padding (Best to set UIGridLayout to Horizontal Cente

0

That's not the problem, I just fixed my code by putting it in a local script. Thank you anyways.

This discussion is preserved as it was. New answers, comments, and votes are closed.