Question by
Andrea_Marchetti · Jul 08, 2017 at 12:23 PM ·
sizeinputfieldlayoutresizing
Input Field inside a Scroll Rect doesn't resize the container.
Please, I am getting crazy.
I have:
Scroll View
--> Viewport
-----> Content
--------> Dynamic Input Field
--------> Static Text
--------> Static Text
--------> Static Text
Resulting Behaviour:
Fine if the text is getting shorter. Bad is the text is getting longer: the dynamic input field content is overlapped by the static texts. NOTE: The text is inserted through code. If I insert it manually into the Input Field everything works fine.
My idea is that it needs to be redrawn, because the same behaviour happens in the editor but when I do something that update the scene view then it resizes correctly.
screen-shot-2017-07-08-at-141228.png
(51.9 kB)
screen-shot-2017-07-08-at-141357.png
(74.2 kB)
Comment
Best Answer
Answer by Andrea_Marchetti · Jul 09, 2017 at 08:07 AM
This is how I resolved it. It looks kind of ugly but it works perfectly.
void Awake ()
{
inputField.text = myRandomText;
StartCoroutine(ForceContainerToRecalculateLayout());
}
private IEnumerator ForceContainerToRecalculateLayout ()
{
yield return new WaitForEndOfFrame ();
container.GetComponent<VerticalLayoutGroup>().childForceExpandHeight = false;
yield return new WaitForEndOfFrame ();
container.GetComponent<VerticalLayoutGroup> ().childForceExpandHeight = true;
}