我想以表格布局显示数据。数据数量是动态的,所以我需要在表中实现动态行。为此,我想在一行中显示 4 个 TextView。
Problem
目前,我能够在表中和四个 TextView 中显示数据,但我希望所有四个 EditText 之间有一些空格,但无法做到这一点。
这是我的代码
for(ItemRow row : this.getRows()) {
if(row != null) {
// delcare a new row
newRow = new TableRow(this);
newRow.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
newRow.setPadding(0, 2, 0, 2);
column1 = new TextView(this);
column2 = new TextView(this);
column3 = new TextView(this);
column4 = new TextView(this);
column1.setTextColor(Color.BLACK);
column2.setTextColor(Color.BLACK);
column3.setTextColor(Color.BLACK);
column4.setTextColor(Color.BLACK);
column1.setSingleLine(false);
column2.setSingleLine(false);
column3.setSingleLine(false);
column4.setSingleLine(false);
if(row.getColumnOne() != null){
column1.setText(row.getColumnOne());
}
if(row.getColumnTwo() != null) {
column2.setText(row.getColumnTwo());
}
if(row.getColumnThree() != null) {
column3.setText(row.getColumnThree());
}
if(row.getColumnFour() != null) {
column4.setText(row.getColumnFour());
}
//Now add a row
newRow.addView(column1);
newRow.addView(column2);
newRow.addView(column3);
newRow.addView(column4);
//Add row to table
table.addView(newRow, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
这是我的输出:
Need
我需要列之间的空格。我该怎么做?
为每个文本视图小部件设置左内边距 5dp,例如android:paddingLeft="5dp"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)