Aru*_*l T 0 android android-layout
我有一个9行的表格布局.第一个是标题.但是列的数量不同.所以我需要动态地将textview添加到表格行.我填充表格行并添加固定的第一列的文本.其他coulmns iam试图在循环中添加它.但我只得到第一个细胞.
我的预期出局是这样的:
col# A B C D E F
----------------------------
1 65 6 6 5 6 7
----------------------------
2 6 4 7 4 6 8
Run Code Online (Sandbox Code Playgroud)
列的数量不能是3到6.但行数是8
我得到这样的出局:
col#
----------------------------
1
----------------------------
2
Run Code Online (Sandbox Code Playgroud)
我试图显示第一行.但我只得到第一个细胞.任何人都可以帮忙吗?
我的xml有一个表行
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="@+id/sn4"
android:textSize="25sp"
android:layout_marginTop="15dip"
android:layout_marginLeft="20dip"
style="@style/normalText"
android:textColor="@color/title"
/>
</TableRow>
Run Code Online (Sandbox Code Playgroud)
我有另一个xml的textview
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txtfactor"
android:textSize="25sp"
android:layout_marginTop="15dip"
android:layout_marginLeft="20dip"
style="@style/normalText"
android:textColor="@color/title"
/>
Run Code Online (Sandbox Code Playgroud)
在我的代码中:
tbl =(TableLayout)findViewById(R.id.tbltrail); for(int i = 0; i <= noOfTrials; i ++){TableRow child =(TableRow)getLayoutInflater().inflate(R.layout.trial_table,null); child.setId(ⅰ); TextView sno =(TextView)child.findViewById(R.id.sn4); if(i == 0){sno.setText("Col#");
for(int j=0; j<count; j++){
FactorObj factorObj = factorList.get(i);
View row = (View) getLayoutInflater().inflate(R.layout.trial_row_content, null);
TextView factorname = (TextView)row.findViewById(R.id.txtfactor);
factorname.setId(200+j);
Log.v(null, "factor name "+factorObj.getFactorName());
factorname.setText("sdf");
child.addView(row);
}
tbl.addView(child);
}else{
sno.setText(String.valueOf(i));
for(int j=0; j<count; j++){
FactorObj factorObj = factorList.get(i);
View row = (View)
getLayoutInflater().inflate(R.layout.trial_row_content, null);
TextView factorname = (TextView)row.findViewById(R.id.txtfactor);
factorname.setId(100+j);
factorname.setText("ss");
child.addView(row);
}
tbl.addView(child);
}
}
Run Code Online (Sandbox Code Playgroud)
为此创建一个视图组行
mCell = new CellViewGroup(this,parameters);
Run Code Online (Sandbox Code Playgroud)
并从xml中引用表格布局
mTableLayout = (TableLayout) findViewById(R.id.mytable);
Run Code Online (Sandbox Code Playgroud)
动态创建表行
TableRow mRow = new TableRow(this);
Run Code Online (Sandbox Code Playgroud)
将视图组添加到该行
mRow.addView(mCell);
Run Code Online (Sandbox Code Playgroud)
将其添加到表格布局中
mTableLayout.addView(mRow);
Run Code Online (Sandbox Code Playgroud)
如果你不知道viewgroup只是google它.....
| 归档时间: |
|
| 查看次数: |
3776 次 |
| 最近记录: |