Scaling a Scrolling frame with a list layout

Hi I was wondering if it is possible to scale a scrolling frames based on the number of elements inside of the UI list layout.
Edit:
tip: if you dont want the Y size of the GUI being used in the list layout UI to change when the scrolling canvas is resized based on the content size, then make the size constraint relative to XX

2 Likes

You can use UIListLayout.AbsoluteContentSize, and scale the canvas of the ScrollingFrame:

local frame = --scrolling frame
local listlayout = -- list layout parented to frame

local contentsize = listlayout.AbsoluteContentSize
frame.CanvasSize = UDim2.new(0,contentsize.X,0,contentsize.Y)
2 Likes

This question has been asked before

1 Like

Scripting support

Welcome to #scripting-support! Please make use of the search bar (Magnifying glass) and search your question to see if it has been asked before you ask it. That way, the forum is not filled with a bunch of duplicate topics, confusing those in the future.


The Code & Explanation

Every time you add or remove a element, update to the new size. Using UIListLayout.AbsoluteContentSize, you can get the size of the frame elements. The code below also supports both horizontal and vertical scrolling elements.

frame (the frame) and ui (the list layout) should be defined.

local frame = -- the frame
local ui = -- list layout

local function UpdateSize()
    wait()--Ui list layouts can sometimes take time to update 
    local cS = ui.AbsoluteContentSize --X = x pixels, Y = Y pixels
    frame.CanvasSize = UDim2.new(0,cS.X,0,cS.Y) --Change that UDim into a UDim2
end

frame.ChildAdded:Connect(updateSize)
frame.ChildRemoved:Connect(updateSize)
updateSize()
16 Likes

I still have a problem with this code because my text buttons are scaled base on the size of the scrolling frame so when i change the size of the scrolling frame it shrinks the size of the textbutton. I knew about the content size from before i should have been more specific sorry

Edited:
i found a solution to my problem and added it to the post for anyone that has this issue in the future

2 Likes

Just wanted to add: You could instead of using XX, use XY and set the position like this:
{0,10},{1,0}

The 10 could be 0.1*Frame.AbsoluteSize.Y, and it would be 1/10 of the visible frame’s size. Just wanted to add that this is also possible, glad you found your solution.

2 Likes