2012-06-08 56 views
0

我正在以编程方式创建表格行,并且希望将之前创建的视图放入行中。有什么办法可以做到吗?如何在Android中的表行中放置自定义视图?

for (current = 0; current < rapor1.length; current++) 
    { 

     TableRow tr = new TableRow(this); 
     tr.setId(100+current); 
     tr.setLayoutParams(new LayoutParams(
       LayoutParams.FILL_PARENT, 
       LayoutParams.WRAP_CONTENT)); 

     TextView f1 = new TextView(this); 
     f1.setId(200+current); 
     f1.setText(rapor1[current]); 
     f1.setTextColor(Color.BLACK); 
     f1.setWidth(100); 
     tr.addView(f1); 

     DrawView dv = new DrawView(this); 
     tr.addView(dv); 

它应该工作,但有些事情是错误的。

+1

什么是错的任何观点及?编译错误?运行时错误?提供更多信息 – theAlse

+0

它不会在那里添加。它不起作用 – mucisk

回答

0

我认为这可能有帮助。只要改变这个字符串:

​​

当然,你需要的LayoutParams设置为你想显示你的屏幕

+0

我试过了。没有工作... – mucisk

+0

以及你没有为textview和drawview设置布局参数,它可能会导致问题,它的布局参数应该写成像'TableRow.LayoutParams'要么 – user1049280

+0

DrawView dv = new DrawView(this); dv.setLayoutParams(new LayoutParams(20,20)); tr.addView(dv); 我试过仍然没有工作... – mucisk

相关问题