2012-06-08 61 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

相關問題