title: Unity UI scrollview returns to original position or goes out of bounds
body: <p>In the UI of my Unity game I plan to dynamically create a scroll with buttons. To do so, I have created a function which returns a button, and then I add it to the scroll. However, when I add multiple buttons and try to scroll, it happens that:
  1) If the scroll is clamped, it does not move.
  2) If the scroll is elastic, it always return to the initial position.
  3) If the scroll is unrestricted, it goes out of bounds (can move indefinitely before and after the first button)</p>
  
  <p>Is there a way to configure the scroll view so it can move within bounds and does not restart its position (i.e., like a normal scroll).</p>
  
  <p>I have created the following functions (I have removed non-relevant parts of the code).
  This creates a button:</p>
  
  <pre><code>private static GameObject CreateElementButton(Element elem, GameObject target)
  {
      DefaultControls.Resources uiResources = new DefaultControls.Resources();
      GameObject button = DefaultControls.CreateButton(uiResources);
  
      RectTransform buttonTransform = button.GetComponent&lt;RectTransform&gt;();
      buttonTransform.sizeDelta = new Vector2(70.0f, 100.0f);
      button.GetComponentInChildren&lt;Text&gt;().text = elem.name;
      button.GetComponentInChildren&lt;Text&gt;().alignment = TextAnchor.LowerCenter;
      button.GetComponentInChildren&lt;Text&gt;().alignByGeometry = true;
  
      Sprite buttonImage = Resources.Load&lt;Sprite&gt;(elem.image);
      button.GetComponent&lt;Image&gt;().sprite = buttonImage;
      button.GetComponent&lt;Image&gt;().type = Image.Type.Filled;
      button.GetComponent&lt;Image&gt;().preserveAspect = true;
  
      return button;
  }
  </code></pre>
  
  <p>This adds it to the scroll view:</p>
  
  <p>public static Element AddElement(string element)
      {
          Element elem = ElementManager.GetElement(element);</p>
  
  <pre><code>    //Get the Scroll
      Transform rightScrollContent = GameObject.Find("RightScrollContent").GetComponent&lt;Transform&gt;();
      GameObject rightSelectedButton = GameObject.Find("RightButton");
  
      //This creates the button to insert to the scroll view.
      GameObject rightButton = InterfaceManager.CreateElementButton(elem, rightSelectedButton);
  
      //I have already tried using rightScrollContent.transform without success.
      rightButton.transform.SetParent(rightScrollContent, false);
  
      return elem;
  }
  </code></pre>
  
  <p>And a screenshot with the definition of the "RightScrollContent" element.</p>
  
  <p><a href="https://i.stack.imgur.com/gV26X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gV26X.png" alt="Element scroll"></a></p>
  
  <p>Can someone spot any error in my code, or point me to a good resource on how to dynamically add buttons to a scroll? Thanks.</p>