0
我正在使用TableLayout,我想动态创建多达50行 我的行有一个图像视图和文本视图,我在OnStart()方法中创建了50个动态行通过使用for循环这是我的代码...,这是最好的做法吗?任何一个可以告诉我这是做到这一点的最好办法,或者你可以参考我的链接android在TableLayout中创建浮动行的最佳方式
public void onStart() {
{
//Items is Array list of 50 objects
TableLayout myTable= (TableLayout)findViewById(R.id.myTableLayout);
for (int i=0;i<Items.size();i++)
{
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
TextView rowText= new TextView(this);
rowText.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
rowText.setText("dyanamic text");
ImageView rowImg = new ImageView(this);
rowImg.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
Bundle extras = getIntent().getExtras();
Drawable dra = Drawable.createFromPath(extras.getString("IconImagePath"));
rowImg.setImageDrawable(dra);
tableRow.addView(rowImg);
tableRow.addView(rowText);
myTable.addView(tableRow);
}
}