I'm trying to write a simple android application, In the app, I have a blank TableLayout
in the xml file, and I'm dynamically (through java code) adding TableRow
s to the table, and Buttons to the table rows. the buttons all have background images.
Everything's perfectly fine, except the size. I want the table to fit the screen but I've had a hard time resizing the whole thing. The best I've been able to do was make the individual buttons smaller by giving them a specific size, which isn't really helpful because of different screen sizes.
I've tried to use the LayoutParams
and the MATCH_PARENT
parameters but it doesn't seem to do anything.
My code is something like this:
....
TableLayout table = findViewById(R.id.table);
for (int i = 0; i < count; i++) {
TableRow row = new TableRow(this);
for (int j = 0; j < count; j++) {
Button cell = new Button(this);
cell.setBackgroundResource(R.drawable.cell_background);
row.addView(cell);
}
table.addView(row);
}
How can I make the cells adjust their size according to the screen?