- Home /
AutoLayout Problem with 2 children
I have a simple problem which seems really difficult to solve the way I'm trying to do it. How would one get 2 children to fit a parent if one has an aspect ratio fitter. These are UI elements in the canvas.
I have a row that is somewhat long that has 2 children; Left one has to fit the height and stay a square (I use AspectRatioFitter), right one has to fill the rest of the width.
EX. Parent is 40x160 Left Child would be 40x40, Right Child would be 40x120 to the right
How do I set this up using the AutoLayout Classes(Hor/Vert/Grid Layout, AspectRatioFitter,ContentSizeFitter)?
Answer by Siniarski · Jan 18, 2017 at 08:23 AM
Well I still have not found a solution using what I described before. I have just expanded the script I have on my parent to handle component resizing using the OnRectTransformDimensionsChanged callback. Working well for all the different dimension changes I make. Hopefully this will help someone.
void OnRectTransformDimensionsChange(){
//Resize children here
preview.GetComponent<RectTransform> ().rect.width;
text.GetComponent<RectTransform> ().sizeDelta = GetComponent<RectTransform> ().sizeDelta+(Vector2.left*left_width));
}
Answer by Harinezumi · Apr 17, 2017 at 11:54 AM
I think you want a flow layout. Simie created a FlowLayoutGroup component and kindly made it open source! :) You can check out here how it works to see if this is what you want, and then get it from here.
I hope it helps!
Your answer
Follow this Question
Related Questions
Change size of UI canvas image, the best option? 1 Answer
Screen Space - Camera Bug (Buttons does not work) on Unity 2017 0 Answers
New UI(=uGUI) depth problem with particle 0 Answers
How to set the UI Text position to be relative to his "grandfather" prefab 0 Answers
Add smooth parts to UI.Image 1 Answer