You should create 3x TableRows in the TableLayout. And place your buttons in these rows. Look at this table layout tutorial.
As it is, you are simply using the TableLayout incorrectly. So you can see virtually anything.
I have done an activity that created a large table of things two years ago.
Look at the code here
/**
* the current row of the currently selected element (starting by 0)
* @return
*/
int currentRow(int position) {
int numOnPage = position - leftTopNumber;
return numOnPage - currentColumn(position) * rowsNumber;
}
/**
* the current column of the currently selected element (starting by 0)
* @return
*/
int currentColumn(int position) {
int numOnPage = position - leftTopNumber;
return numOnPage / rowsNumber;
}
/**
* setting width and height for a ViewGroup instance
* @param viewGroup instance to be changed
* @param width if it is 0, the ViewGroup instance width remains as it was
* @param height if it is 0, the ViewGroup instance height remains as it was
*/
static void setMeasures(ViewGroup viewGroup, int width, int height) {
LayoutParams params = viewGroup.getLayoutParams();
if (width != 0) params.width = width;
if (height != 0) params.height = height;
viewGroup.setLayoutParams(params);
}
@Override
public void onResume() {
super.onResume();
}
static private LinearLayout table;
static private TextView leftTriangle, rightTriangle;
boolean fillTableByCells() {
int i = 0, j = 0;
try {
final LayoutInflater inflater =
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
setContentView(R.layout.channels_list_table);
LinearLayout allForm = (LinearLayout) findViewById(R.id.AllChannelsListForm);
LinearLayout upperMargin = (LinearLayout) findViewById(R.id.UpperMargin);
LinearLayout middleStripe = (LinearLayout) findViewById(R.id.MiddleStripe);
LinearLayout bottomMargin = (LinearLayout) findViewById(R.id.BottomMargin);
RelativeLayout leftMargin = (RelativeLayout) findViewById(R.id.LeftMargin);
LinearLayout tableWrapper = (LinearLayout) findViewById(R.id.CentralFieldWrapper);
RelativeLayout rightMargin = (RelativeLayout) findViewById(R.id.RightMargin);
tvComposeNumber = (TextView) findViewById(R.id.tvComposeNumber);
leftTriangle = (TextView) findViewById(R.id.TriangleLeft);
rightTriangle = (TextView) findViewById(R.id.TriangleRight);
table = (LinearLayout) findViewById(R.id.table_channels);
allForm.measure(0, 0);
int formWidth = allForm.getWidth();
int formHeight = allForm.getHeight();
formWidth = 960;
formHeight = 540;
int heightUpper = formHeight * 66 / 570;
int heightMiddle = formHeight * 410 / 570;
int heightBottom = formHeight * 94 / 570;
int widthLeft = formWidth * 60 / 1140;
int widthMiddle = formWidth * 1020 / 1140;
int widthRight = formWidth * 60 / 1140;
setMeasures(allForm, formWidth, formHeight);
setMeasures(upperMargin, formWidth, heightUpper);
setMeasures(middleStripe, formWidth, heightMiddle);
setMeasures(bottomMargin, formWidth, heightBottom);
setMeasures(leftMargin, widthLeft, heightMiddle);
setMeasures(tableWrapper, widthMiddle, heightMiddle);
setMeasures(rightMargin, widthRight, heightMiddle);
LinearLayout.LayoutParams wrapperLP =
(LinearLayout.LayoutParams) tableWrapper.getLayoutParams();
LinearLayout.LayoutParams tableLP = (LinearLayout.LayoutParams) table.getLayoutParams();
int widthInsideTable =
widthMiddle - wrapperLP.leftMargin - wrapperLP.rightMargin
- tableWrapper.getPaddingLeft() - tableWrapper.getPaddingRight()
- tableLP.leftMargin - tableLP.rightMargin - table.getPaddingLeft()
- table.getPaddingRight();
// setMeasures(table,widthMiddle,heightMiddle);
cellsNumber = TvChannel.list.size();
columnsNumber = (cellsNumber - 1) / rowsNumber + 1;
for (i = 0; i < columnsNumber; i++) {
LinearLayout column =
(LinearLayout) inflater
.inflate(R.layout.channels_list_column, table, false);
table.addView(column, i);
for (j = 0; j < rowsNumber; j++) {
int numberChannel = i * rowsNumber + j;
if (numberChannel >= TvChannel.list.size()) break;
LinearLayout cell =
(LinearLayout) inflater.inflate(R.layout.channels_list_cell, column,
false);
column.addView(cell, j);
TextView numberChannelView = (TextView) cell.getChildAt(0);
TextView nameChannelView = (TextView) cell.getChildAt(1);
nameChannelView.setText(TvChannel.list.get(numberChannel).name);
String numberString = String.format("%d", i * rowsNumber + j);
numberChannelView.setTextSize(new float[] { 22f, 20f, 17f }[numberString
.length() - 1]);
numberChannelView.setText(numberString);
cell.setVisibility(View.VISIBLE);
}
// column.setLayoutParams(new
// LayoutParams(tableWidth/3,LayoutParams.MATCH_PARENT));
LinearLayout.LayoutParams columnLP =
(LinearLayout.LayoutParams) column.getLayoutParams();
int colWidth =
widthInsideTable / maxSeenColumns - columnLP.leftMargin
- columnLP.rightMargin;
setMeasures(column, colWidth, LayoutParams.MATCH_PARENT);
for (int iCell = 0; iCell < column.getChildCount(); iCell++) {
LinearLayout cell = (LinearLayout) column.getChildAt(iCell);
setMeasures(cell, LayoutParams.MATCH_PARENT,
(heightMiddle - column.getPaddingBottom() * 2) / rowsNumber);
}
}
return true;
}
catch (Throwable e) {
ErrorMessage.outputMessageByName("channels_list_activity_create", this, e.toString()
+ "; column=" + i + "; row=" + j);
finish();
return false;
}
}