2013-07-02 39 views
0

在ScrollView中我有一個LinearLayout。在這個LinearLayout中,我不能添加帶有索引的視圖。帶索引錯誤的LinearLayout addView

爲什麼?

例如:

RelativeLayout relativeLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.android_messenger_sent_message, null); 
TextView inbox_message = (TextView)relativeLayout.findViewById(R.id.sentMessage); 
inbox_message.setText(conversationInfo.getBody()+" "+conversationInfo.getId()); 
linearLayoutGlobal.addView(relativeLayout,i); 

其中i爲1 000 000的整數,它正變得越來越小

回答

2

不能添加到位置1 000 000如果沒有意見。 :)嘗試使用addView(relativeLayout)而不是索引版本。

如果您需要按相反順序添加,請使用addView(relativeLayout, 0)。這將繼續插入名單的頭上,因此拋棄了後面的意見。

注意:將1M視圖添加到單個滾動視圖肯定會因爲耗盡資源而失敗。嘗試用較低的數字或更改爲ListView

+0

這不是完全解決我的問題,但我用它並改變了我的代碼在這裏和那裏。謝謝! –