我正在尝试将 TableRows 添加到运行良好的 TableLayout 中。但是,我在布局参数方面遇到了一些问题。TableRow 中 TextView 之间的间距不像我想象的那样正常。
我当前的代码如下所示。
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 看起来类似于:
January$500
February$500
March$405
但我希望它看起来像:
January $500
February $500
March $405
为了澄清事情,我希望每个新的 TableRow 和它包含的 TextViews 继承现有 TableRow 和 TextView(s) 的布局属性。