title: TableLayout programmatically
body: <p>We want to instantiate a <code>TableLayout</code> programmatically with an <code>undefined</code> number of rows and buttons. We have developed the following code but when we open the app it doesn't show all the buttons (the table is much bigger than the screen).</p>
  
  <pre><code>private void setButtons() {
      TableLayout table = (TableLayout) view.findViewById(R.id.table);
      TableRow row;
      TableLayout.LayoutParams lp = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT);
      lp.bottomMargin = 32;
      lp.topMargin = 32;
      LevelButton button;
  
      for (int i = 0; i &lt; Constants.ROW_NUM; i++) {
          row = new TableRow(table.getContext());
          row.setLayoutParams(lp);
          row.setGravity(Gravity.CENTER | Gravity.BOTTOM);
  
          for (int j = 0; j &lt; Constants.BUTTON_NUM; j++) {
              button = new LevelButton(row.getContext());
              TableRow.LayoutParams lpb = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT);
              lpb.leftMargin = 32;
              lpb.rightMargin = 32;
              button.setLayoutParams(lpb);
              button.setLevelNumber((i*6)+j+1);
              if (j == 1) {
                  button.setState(LevelState.ZERO_STARS);
              }
              row.addView(button);
              Log.println(Log.DEBUG, "debug", "" + row.getLayoutParams().height);
          }
          table.addView(row);
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/u4yQ9.png" alt="Screen view"></p>