[英]Problem to display dynamic rows in table layout : Android
我想在表格布局中顯示數據。 數據的數量是動態的,所以我需要在表中實現動態行。 為此,我想在一行中顯示 4 個 TextView。
問題
目前,我能夠在表中顯示數據並使用四個 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));
}
}
這是我的 output:
需要
我需要列之間的空格。 我該怎么做?
為每個 textveiw 小部件設置左填充 5dp,例如android:paddingLeft="5dp"
您還必須為列添加 paddind:
column1.setPadding(5, 5, 5, 5);
column2.setPadding(5, 5, 5, 5);
column3.setPadding(5, 5, 5, 5);
column4.setPadding(5, 5, 5, 5);
編輯:然后你可以設置 layoutparams 如下:
column1.setLayoutParams(new LinearLayout.LayoutParams(60,90));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.