I am trying to create a GridLayout with 16 x 16 buttons in it, but I can't remove the spaces between the buttons.
I saw this but it didn't work.
Here's what I'm trying now:
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
GridLayout v = (GridLayout)findViewById(R.id.myGrid);
v.setPadding(0, 0, 0, 0);
v.setUseDefaultMargins(false);
v.setAlignmentMode(GridLayout.ALIGN_BOUNDS);
v.setRowOrderPreserved(false);
Random r = new Random();
for (int row = 0; row < 16; row++)
for (int col = 0; col < 16; col++) {
GridLayout.LayoutParams lp = new GridLayout.LayoutParams();
lp.setMargins(0, 0, 0, 0);
lp.rowSpec = GridLayout.spec(row);
lp.columnSpec = GridLayout.spec(col);
lp.width = 40;
lp.height = 40;
Button b = new Button(this);
b.setWidth(40);
b.setHeight(40);
b.setText(Integer.toString(r.nextInt(10)));
b.setPadding(0, 0, 0, 0);
b.setLayoutParams(lp);
v.addView(b, lp);
}
}
Screenshot
Any idea what's wrong?
EDIT: I changed the background of some buttons to a green picture is this is what I got:
Apparently the spacing is part of the button image... Why Android, why?