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)?
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));
}
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!