Scrolling frame fit perfectly based on how many frames are in it using UIListLayout

Hey! I am here wanting to see how I could make a scrolling frame on the X scrolling direction change the CanvasSize based on how many frames are in it, that get sorted using a UIListLayout.


Some solutions I have tried have been Devforum, I found a couple posts about it but I couldn’t seem to figure it out, said something about UIGridLayout but I am not sure what that is or if it is necessary for my situation.

Basically I just am wondering if it’s possible and how, to make it if there are only a couple frames in the scrolling frame, that you cannot scroll at all. But if theres lots of frames in the scrolling frame, that it goes of screen that it makes you scroll only enough to see all of the frames.

2 Likes

Set the AutomaticCanvasSize propety to X, then set the normal canvas size to {0,0,0,0}, that’s what I always do. Roblox will then automatically calculate the suitable canvas size for you so that it can fit all the objects perfectly. In some cases, you may need to resize your frames.

1 Like

The issue is that I can’t edit any of the absolute’s, so how do I set it to X?
image
(This is in the scrolling frame.)

1 Like

I think you may have read my message wrong, I mentioned that you need to change AutomaticCanvasSize. In roblox, you are not able to change the absolute values.

Okay, I did what you said, sorry for the misunderstanding. But now when I add more frames that it takes the whole thing up, the scroll wheel isn’t coming back:

image

1 Like

Sometimes it does that, could you show me what’s inside of the objects and their properties?
image

1 Like

Yes, here you go. This is what is in all of them.
image

Could you also provide their properties? For me it’s working fine

Main Frame:


Play Button:


Star Button:


I also just tested it using a frame, and it works so it must be something with the properties…?

Sorry for the late response, it could possibly be the UI Aspect ratio constraint. You could try temporarily removing it to see if it works, and also the padding property on the ui list layout could cause problems as well. The automatic canvas size property is just very glitchy as you can see.

Alright. I removed the UI Aspect ratio constraint, and it fixed the issue. But is there a way to keep the constraint and it work? It just makes the UI look a lot better on mobile devices.

This is the difference without it:
image

1 Like

Actually wait. I just tested it with a frame, and added a constraint, and it worked. Now I am confused.

1 Like

Normally you are able to add a constraint, maybe add it again and mess with the size or remove the frame from the scroller and add it back?

I’m trying to help but it looks like roblox is buggy with these kinds of things.

1 Like

Hmmmm. I was playing with it a bit, and when I removed the two buttons inside the frame. (Play button and star button) it worked even with the constraint.

Alright, I figured it out with a little script,

local scrollingFrame = script.Parent
local UIListLayout = scrollingFrame.GameTemplates.UIListLayout

scrollingFrame.CanvasSize = UDim2.new(0, UIListLayout.AbsoluteContentSize.X, 0, 0) -- This makes sure the scrolling frame is scaled when the game starts.

local function onContentSizeChanged()
	print("Debug1")
	scrollingFrame.CanvasSize = UDim2.new(0, UIListLayout.AbsoluteContentSize.X, 0, 0) -- This makes sure the scrolling frame is scaled when ever there is something added into it during the game.
end

UIListLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(onContentSizeChanged)

Thanks a lot!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.