0
A
回答
1
試試這個..
TableLayout tableLayout = new TableLayout(this);
tableLayout.setStretchAllColumns(true);
tableLayout.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT));
tableLayout.setWeightSum(3);
for (int i = 0; i < 3; i++) {
TableRow tableRow = new TableRow(this);
tableRow.setGravity(Gravity.CENTER);
tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT, 1.0f));
for (int j = 0; j < 3; j++) {
TextView button = new TextView(this);
final int buttonNumber = (j + i * 4);
button.setText("" + buttonNumber);
button.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.FILL_PARENT));
tableRow.addView(button);
}
tableLayout.addView(tableRow);
}
main_lay.addView(tableLayout);
1
TableLayout table = (TableLayout) findViewById(R.id.TableName);
TableRow tableRow = new TableRow(context);
tableRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
TextView cell1= new TextView(getApplicationContext());
cell1.setText("one");
cell1.setTextColor(Color.BLACK);
cell1.setTextSize(16f);
cell1.setTypeface(tf);
TextView cell2= new TextView(getApplicationContext());
cell2.setText("two");
cell2.setTextColor(Color.BLACK);
cell2.setTextSize(16f);
cell2.setTypeface(tf);
TextView cell3= new TextView(getApplicationContext());
cell3.setText("three");
cell3.setTextColor(Color.BLACK);
cell3.setTextSize(16f);
cell3.setTypeface(tf);
tableRow.addView(cell1);
tableRow.addView(cell2);
tableRow.addView(cell3);
talbe.addView(tableRow , new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
0
如果你想要的話,你可以使用這樣的函數來更新你的tableLayout,其中添加了一些帶有文本的新行。
private void addRowToTableLayout(TableLayout tableLayout, String text){
TableRow tr = new TableRow(MyActivity.this);
//if you want you can customize the table row
tr.setBackgroundColor(getResources().getColor(R.color.backgroundColor));
tr.setLayoutParams(new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.WRAP_CONTENT));
TextView textView = new TextView(MyActivity.this);
//if you want you can customize the textview also
textView.setText(text);
tr.addView(textView);
tableLayout.addView(tr, new TableLayout.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
}
相關問題
- 1. 添加到表格Android TableLayout
- 2. 動態行添加到TableLayout
- 3. TableLayout單元格定位
- 4. 試圖將行和單元格動態添加到表格
- 5. 在Android中動態添加行到TableLayout
- 6. 用Javascript添加元素到單元格
- 7. ArithmeticException當用行和單元格充氣TableLayout
- 8. 將ScrollView和HorizontalScrollView添加到TableLayout
- 9. 擴展TableLayout類 - 添加行
- 10. 從代碼中添加表格行到TableLayout(刪除父錯誤)
- 11. Tablelayout添加textviews到tablerows
- 12. 如何將NSTableView單元格添加到單元格的填充?
- 13. 將可編輯數字單元格添加到單元格
- 14. 使用Javascript動態添加表格行和單元格
- 15. 爲每個結果= 1添加單元格到表格行?
- 16. 將表格單元添加到現有的表格行jQuery
- 17. 添加和檢索單元格到字典丟失單元格信息swift3
- 18. 將多個單元格添加到單個行中
- 19. 對齊TableLayout單元格內的控件
- 20. OnClickListener for tableLayout中的每個單元格?
- 21. Android TableLayout延伸單元格內容
- 22. TableLayout問題的單元格大小(C#)
- 23. TableLayout的單元格顯示/隱藏
- 24. 將控件添加到Gridview單元格
- 25. 添加一個UIPickerView到UITableView單元格
- 26. 將UIPageControll添加到UITableView單元格
- 27. 將JButton添加到JTable單元格+ DB
- 28. 將單元格值添加到常數
- 29. Android:動態添加單元格到GridView?
- 30. jQuery EasyUI - 添加鏈接到單元格