title: Android - Scrolling Vertically with a GridLayout
body: <p>How can I scroll vertically within a GridLayout? I have already tried using a ScrollView with the GridLayout as a Child, with RelativeLayout children within the GridLayout, but that results in all of the children piling on top of each other and or going outside of the layout.</p>
  
  <p>Before Using the GridLayout in ScrollView:</p>
  
  <p><img src="https://i.stack.imgur.com/AdtEg.png" alt="Before"></p>
  
  <p>After GridLayout in ScrollView:</p>
  
  <p><img src="https://i.stack.imgur.com/eoUDG.png" alt="After"></p>
  
  <p>I need to achieve that effect with the GridLayout inside the ScrollView as a Child</p>
  
  <p>My XML layout file:</p>
  
  <pre><code>&lt;ScrollView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:fillViewport="true"&gt;
  
      &lt;LinearLayout
          android:id="@+id/boxContainer"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"&gt;
  
          &lt;GridLayout
              android:layout_width="wrap_content"
              android:layout_height="315dp"&gt;
  
              &lt;!-- RelativeLayout children go here --&gt;
  
          &lt;/GridLayout&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>I am initialising them in OnCreate with LayoutParams:</p>
  
  <pre><code>//MiddleLayout
          GridLayout.LayoutParams middleLayoutLayoutParams = (GridLayout.LayoutParams)middleLayout.getLayoutParams();
          middleLayoutLayoutParams.setMargins(2, 273, 400, 0);
          middleLayoutLayoutParams.setGravity(Gravity.LEFT);
          middleLayoutLayoutParams.width = 424;
          middleLayout.setLayoutParams(middleLayoutLayoutParams);
          middleLayout.setBackgroundDrawable(new ColorDrawable(Color.RED));
          middleLayout.bringToFront();
  
          //MiddleLayout1
          GridLayout.LayoutParams middleLayoutLayoutParams1 = (GridLayout.LayoutParams)middleLayout1.getLayoutParams();
          middleLayoutLayoutParams1.setMargins(431, 273, -2, 0);
          middleLayout1.getLayoutParams().width = 645;
          middleLayout1.setLayoutParams(middleLayoutLayoutParams1);
          middleLayout1.setBackgroundDrawable(new ColorDrawable(Color.GREEN));
  
          //TopLayout
          GridLayout.LayoutParams topLayoutLayoutParams = (GridLayout.LayoutParams)topLayout.getLayoutParams();
          topLayoutLayoutParams.setMargins(2, 0, -2, 676);
          topLayout.getLayoutParams().width = 631;
          topLayout.setLayoutParams(topLayoutLayoutParams);
          topLayout.setBackgroundDrawable(new ColorDrawable(Color.rgb(255, 154, 0)));
  
          //TopLayout1
          GridLayout.LayoutParams topLayoutLayoutParams1 = (GridLayout.LayoutParams)topLayout1.getLayoutParams();
          topLayoutLayoutParams1.setMargins(638, 0, -2, 676);
          topLayout1.getLayoutParams().width = 440;
          topLayout1.setLayoutParams(topLayoutLayoutParams1);
          topLayout1.setBackgroundDrawable(new ColorDrawable(Color.BLUE));
  
          //bottomLayout
          GridLayout.LayoutParams bottomLayoutLayoutParams = (GridLayout.LayoutParams)bottomLayout.getLayoutParams();
          bottomLayoutLayoutParams.setMargins(2, 0, -2, 2);
          bottomLayout.getLayoutParams().width = 1073;
          bottomLayout.setLayoutParams(bottomLayoutLayoutParams);
          bottomLayout.setBackgroundDrawable(new ColorDrawable(Color.rgb(0, 0, 153)));
  </code></pre>
  
  <p>Any idea how I can get these to display properly within a GridLayout, or create the ScrollView/GridLayout Programatically?</p>
  
  <p>Thanks!</p>