I am trying to change the button size dynamically, but after using setWidth() and setHeight() nothing happens.
This is my code…
GridLayout grid = (GridLayout)findViewById(R.id.grid);
grid.setColumnCount(10);
grid.setRowCount(10);
cells = new Button[100];
for (int i = 0; i < cells.length; i++) {
cells[i] = new Button(this);
cells[i].setWidth(grid.getWidth()/10);
cells[i].setHeight(grid.getHeight()/10);
grid.addView(cells[i]);
}
Any ideas/solutions?
I figured this out on my own and it was very simple, I feel stupid for overlooking it.
In this line of code I add the button to the layout with the “cells[i]” while the trailing two parameters tell the view what size I want the button to be.
Another example:
Above the addView is adding myButton with 100 pixel width by 200 pixel height.