This is my decision:

table_divider.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="0dp" />
<solid android:color="#FFFFFF" />
<stroke android:width="1px" android:color="#AAAAAA" />
</shape>
Fill in the table for any list of objects:
private void fillTable(List<MenuItem> items) {
TableLayout tl = (TableLayout)findViewById(R.id.main_content_button_container);
TableRow tr = new TableRow(this);
int count = 0;
for (MenuItem item : items) {
TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
LinearLayout borderView = new LinearLayout(this);
int topMargin = count < 2 ? 1 : -1;
if ((count%2) == 0) {
tr = new TableRow(this);
tableRowParams.setMargins(0,topMargin,0,0);
borderView.setLayoutParams(tableRowParams);
borderView.setBackgroundResource(R.drawable.table_divider);
borderView.addView(getButton(item));
tr.addView(borderView);
tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
} else {
tableRowParams.setMargins(-1,topMargin,0,0);
borderView.setLayoutParams(tableRowParams);
borderView.setBackgroundResource(R.drawable.table_divider);
borderView.addView(getButton(item));
tr.addView(borderView);
}
count++;
}
}
Cell contents:
private Button getButton(NqMenuItem item) {
int pixelValue = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 120, getResources().getDisplayMetrics());
Button button = new Button(this);
button.setText(item.title);
button.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_drawer_about, 0, 0);
TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, pixelValue);
button.setBackgroundColor(Color.TRANSPARENT);
button.setLayoutParams(tableRowParams);
button.setPadding(0,30,0,0);
return button;
}
source
share