title: Add buttons dynamically to ScrollView android
body: <p>So I want to add x amount of buttons to a layout in android (where x is usually between 4 and 24), and I can achieve this using the code below, but it doesn't scroll so it cuts off some of the buttons</p>
  
  <p>I am using a fragment, which contains a <code>LinearLayout</code> and <code>BottomNavigation</code>, and one of those navigation options leads to the fragment contained below</p>
  
  <p>At the moment my.xml file looks like:</p>
  
  <pre><code>&lt;ScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;LinearLayout
          android:id="@+id/units_group"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_centerHorizontal="true"
          android:layout_marginEnd="20dp"
          android:layout_marginStart="20dp"
          android:layout_marginTop="20dp"
          android:orientation="vertical"&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p>And my code:</p>
  
  <pre><code> public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      final View view = inflater.inflate(R.layout.fragment_course_units, container, false);
  
      final LinearLayout unitsBtns = (LinearLayout) view.findViewById(R.id.units_group);
  
      //I actually get this from a volley request but didn't want to include all the code
      String[] units = {"1", "2", "3", "4", "5", "6", "7", "8"}; 
  
      for(int i = 0; i &lt; units.length; i++){
          LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                  ViewGroup.LayoutParams.MATCH_PARENT,
                  ViewGroup.LayoutParams.MATCH_PARENT
          );
  
          params.setMargins(0, 30, 0, 0);
          Button b = new Button(getActivity());
  
          b.setLayoutParams(params);
          b.setText(units[i]);
          b.setId(i);
          b.setBackgroundColor(Color.WHITE);
  
          b.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  try {
                      // STUFF HERE
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
          unitsBtns.addView(b);
      }
  
      return view;
  }
  </code></pre>
  
  <p>Is there any way to get the buttons to be scrollable? I have tried to put the <code>scrollView</code> around the parent of this too and it still doesn't seem to work.</p>
  
  <p>Note: I am still pretty new to developing native Android apps so please correct me if I'm doing something incorrectly</p>