2011-10-26 37 views
0

我本來的LinearLayout>滾動型> TableLayout和下面的代碼:滾動型內處理的LinearLayout

LinearLayout layout = (LinearLayout) View.inflate(this, R.layout.photos_layout, null); 
setContentView(layout); 
// TODO Auto-generated method stub 
//get the tableLayout which we created in main.xml 
tl = (TableLayout)findViewById(R.id.tableLayout1); 
for(int i = 0; i < names.length; i++) { 
    //Create a new row to be added. 
    TableRow tr = new TableRow(this); 
    //Create text views to be added to the row. 
    TextView tv1 = new TextView(this); 
    TextView tv2 = new TextView(this); 
    //Put the data into the text view by passing it to a user defined function createView() 
    createView(tr, tv1, Integer.toString(i+1)); 
    createView(tr, tv2, names[i]); 
    //Add the new row to our tableLayout tl 
    tl.addView(tr); 
} 

的問題是一個滾動視圖只能有一個孩子,所以如果我想添加更多的意見除了tableLayout我不能。爲了克服這個問題,我做了像LinearLayout> ScrollView> linearLayout> tableLayout的層次結構。但是,現在上面的代碼崩潰了應用程序。

我需要改變以填充我的表格,以及添加視圖到我新創建的linearlayout?

+1

如果你有崩潰,你應該在這裏包含LogCat輸出 –

+0

發佈崩潰日誌。和一些xmls? –

+0

把你的錯誤記錄下來。 – blessenm

回答

0

我建議刪除父LinearLayout。滾動查看本身可以是父級,然後有一個LinearLayout作爲其唯一的直接子元素。

在你提到的代碼崩潰的代碼中,你沒有添加任何視圖到你的「新創建的」LinearLayout,而是你添加了一個新的行到你的TableLayout,如果我猜對了,在你的滾動視圖中。這非常好,不應該成爲崩潰的原因。

相關問題