1
我想在Android(最低API級別10)中製作一個表,其中一些列必須儘可能伸展,而有些需要縮小以適合其內容的大小。讓TableLayout列完全適合其內容的大小
這是我有:
(顏色也正好看到細胞的寬度和高度)
的‘在’列是什麼,我說什麼。我需要它看起來像這樣的:
http://img268.imageshack.us/img268/1572/77141b8b8eb443d783cede5.png
這裏是我用現在的代碼:
ScrollView sv = new ScrollView(this);
TableLayout table = new TableLayout(this);
table.setShrinkAllColumns(true);
table.setStretchAllColumns(true);
table.setPadding(10, 10, 10, 10);
//title row
TableRow rowTitle = new TableRow(this);
rowTitle.setGravity(Gravity.CENTER_HORIZONTAL);
TextView title = new TextView(this);
title.setText("Majors - Season 10");
title.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
title.setGravity(Gravity.CENTER);
title.setTypeface(Typeface.SERIF, Typeface.BOLD);
TableRow.LayoutParams params = new TableRow.LayoutParams();
params.span = 4;
rowTitle.addView(title, params);
//header row
TableRow rowHeaders = new TableRow(this);
TextView away = new TextView(this);
away.setText("Away");
away.setTypeface(Typeface.DEFAULT_BOLD);
away.setGravity(Gravity.CENTER_HORIZONTAL);
rowHeaders.addView(away);
TextView empty = new TextView(this);
empty.setText(" ");
// empty.setGravity(Gravity.CENTER_HORIZONTAL);
empty.setBackgroundColor(Color.GREEN);
rowHeaders.addView(empty);
TextView home = new TextView(this);
home.setText("Home");
home.setTypeface(Typeface.DEFAULT_BOLD);
home.setGravity(Gravity.CENTER_HORIZONTAL);
rowHeaders.addView(home);
TextView score = new TextView(this);
score.setText("Score");
score.setTypeface(Typeface.DEFAULT_BOLD);
score.setGravity(Gravity.RIGHT);
rowHeaders.addView(score);
TableRow rowMatch = createMatchRow();
TableRow rowMatch2 = createMatchRow();
table.addView(rowTitle);
table.addView(rowHeaders);
table.addView(rowMatch);
table.addView(rowMatch2);
sv.addView(table);
return sv;
createMatchRow()只是一個返回的TableRow每個方法的比賽。 (行2-)