作者DeathDeath (你想洗腳嗎)
看板AndroidDev
標題[問題] 大型表格的顯示與滑動
時間Thu Mar 14 10:24:55 2013
我編寫了一段程式 動態產生一個64x64的TableLayout 以TextView呈現每個表格
然後對每個TextView作屬性設定 最後顯示
結果是成功了...但是顯示速度很慢(約需三秒載入)
而且放在ScrollView底下 滑動起來會很卡
以下是主要程式碼
TableLayout ahha = (TableLayout)findViewById(R.id.testtable);
...
for(int i=0;i<64;i++) {
TableRow row = new TableRow(MainActivity.this);
//row.setBackgroundColor(Color.rgb(i*4,i*4,i*4)); ...(1)
for(int j=0;j<64;j++) {
TextView col = new TextView(MainActivity.this);
col.setHeight(10);
col.setWidth(10);
col.setBackgroundColor(Color.rgb(i*4,i*4,i*4)); ...(2)
row.addView(col);
}
ahha.addView(row);
}
上列程式碼中 (1)和(2)所得的顏色結果會相同
不過滑動起來(1)的速度比(2)快很多
所以我猜原因在於對每個TextView的屬性設定會造成記憶體不足
不知道有沒有人遇過類似的問題 是如何解決的?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.66.115.171
※ 編輯: DeathDeath 來自: 59.66.115.171 (03/14 10:25)
1F:→ lovelycateye:你可能可以參考看看官方AdapterView的一些作法 03/14 10:58
2F:→ lovelycateye:你這樣是把所有東西都弄好,而Adapter是要顯示才弄 03/14 10:58
3F:→ lovelycateye:最接近的可能是GridView吧? 03/14 10:59
4F:→ DeathDeath:小弟是新手 還在摸索怎麼用表格來呈現影像的pixel 03/14 11:00
5F:→ DeathDeath:是不是用你所提到的gridview會比較好呢? 03/14 11:00
6F:→ lovelycateye:影像的pixel? 我的意思是如果真的要自己刻的話 03/14 11:09
7F:→ lovelycateye:作法部分可以參考而已,因為那種作法會比較省記憶體 03/14 11:09
8F:→ lovelycateye:記憶體存的只會有畫面上能夠顯示到的東西而已 03/14 11:10
9F:→ lovelycateye:當然你可以找找看有沒有類似的東西 03/14 11:10
10F:→ hellogg1:同意L大的說法,請使用GridView,它需要搭配 Adapter 03/14 11:32
11F:→ hellogg1:若你需要動態的更動textView所呈現的資訊且資訊量很大 03/14 11:33
12F:→ hellogg1:建議在adapter中新增執行緒去讀取資料,並使用arraylist 03/14 11:34
13F:→ hellogg1:或Vector之類去存這些資訊 03/14 11:34