Android的 - 使用现有的TableRow布局动态地添加到的TableRow TableLayout [英] Android - Dynamically Adding TableRow to TableLayout using an existing TableRow layout
问题描述
我想加入TableRows到TableLayout,这是工作飞驰。然而,我遇到一些问题与布局参数。通过tablerow内TextViews之间的间距不工作,这样我认为会。
I'm trying to adding TableRows to a TableLayout, which is working fantastically. However, I'm running into some problems with layout parameters. The spacing between the TextViews within a TableRow isn't working out like I thought it would.
我目前的code如下所示。
My current code looks as follows.
paymentTable = (TableLayout) findViewById(R.id.paymentTable);
for(i = 0; i < cursor.getCount(); i++) {
TableRow row = new TableRow(this);
TextView payAmount = new TextView(this);
payAmount.setText(cursor.getString(cursor.getColumnIndex(DatabaseHelper.KEY_AMOUNT)));
payAmount.setPadding(payAmount.getPaddingLeft(),
payAmount.getPaddingTop(),
textView.getPaddingRight(),
payAmount.getPaddingBottom());
TextView payDate = new TextView(this);
payDate.setText(cursor.getString(cursor.getColumnIndex(DatabaseHelper.KEY_DATE)));
row.addView(payDate);
row.addView(payAmount);
paymentTable.addView(row, new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
cursor.moveToNext();
}
随后,TableLayout看起来线沿线的东西:
Afterwards, the TableLayout looks something along the lines of:
January$500
February$500
March$405
但我希望它看起来像:
But I want it to look like:
January $500
February $500
March $405
要澄清的东西,我想每一个新的TableRow,它包含继承现有的TableRow和TextView的(S)。
To clarify things, I want each new TableRow and the TextViews it contains to inherit layout properties of an existing TableRow and TextView(s).
推荐答案
yawus这是一个很好的教程将帮助您设置表格的布局
http://www.anotherandroidblog.com/2010/08/04/ Android的数据库教程/
yawus this is a good tutorial will help you set the table layout http://www.anotherandroidblog.com/2010/08/04/android-database-tutorial/
这是XML布局
http://www.anotherandroidblog.com/2010 / 08/04 / Android的数据库教程/ 6 /
这是活动code
http://www.anotherandroidblog.com/2010 / 08/04 / Android的数据库教程/ 8 /
TableRow tableRow= new TableRow(this);
ArrayList<Object> row = data.get(position);
TextView idText = new TextView(this);
idText.setText(row.get(0).toString());
tableRow.addView(idText);
TextView textOne = new TextView(this);
textOne.setText(row.get(1).toString());
tableRow.addView(textOne);
TextView textTwo = new TextView(this);
textTwo.setText(row.get(2).toString());
tableRow.addView(textTwo);
dataTable.addView(tableRow);
这篇关于Android的 - 使用现有的TableRow布局动态地添加到的TableRow TableLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!