Search code examples
androidandroid-viewandroid-buttonandroid-tablelayout

Unable to display all the buttons in TableLayout


I am generating buttons onto the screen programatically This is my code

       TableLayout MainLayout = new TableLayout(this);
    MainLayout.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.MATCH_PARENT));
    //MainLayout.setStretchAllColumns(true);

    for ( int i =0 ; i < gridSize ; i++){
        rowArr[i] = new TableRow(this);
        for(int j = 0; j < gridSize ; j++){

            Button button = new Button(this);
            button.setText(Integer.toString(i)+","+Integer.toString(j));
            button.setTextSize(150/gridSize);
            button.setMaxHeight(450/gridSize);
            button.setMaxWidth(600/gridSize);
            rowArr[i].addView(button);

        }
        MainLayout.addView(rowArr[i]);
    }

enter image description here

By the seeing the image you can an entire column of buttons are missing.

Only after setting my gridSize to 6 or more does this problem occur.


Solution

  • I was able to see the 6th row on my emulator.I guess the phone width was the issue