title: Unity, scalling the width of a dynamically created Gameobject in a a scroll view content box
body: <p>I am trying to add 100 dynamically created buttons to a scroll view in Unity, but I have a problem letting the scroll view automatically adjust the width of the buttons to match the width of my screen.</p>
  <p>When I tried to add the buttons manually it worked fine , but when I do this by code I get another results.</p>
  <p>The code I am using :</p>
  <pre><code>public GameObject button;
  public GameObject scrollviewcontents;
  
  void Start()
  {
      for (int i =0; i&lt;=100;i++) {
    
  
         GameObject dbutton = Instantiate(button);
          dbutton.name = i.ToString();
          dbutton.transform.parent = scrollviewcontents.transform;
      }
  </code></pre>
  <p>}</p>
  <p>and The results I get :
  <a href="https://i.stack.imgur.com/GBFB8.png" rel="nofollow noreferrer">Results</a></p>
  <p><a href="https://i.stack.imgur.com/PYVjw.png" rel="nofollow noreferrer">Results with comments</a></p>
  <p><strong>I just want the buttons to look like as they are added manually</strong>, any help ???</p>