天天看點

android listview 隻加載顯示的圖檔大小,android ListView隻加載目前螢幕顯示的圖檔(解決List滑動時加載卡頓)...

之前寫過一個關于ListView異步加載網絡圖檔的文章:http://blog.sina.com.cn/s/blog_7033e38201010req.html,但是使用時發現如果快速滑動List,因為正在加載圖檔,會有點卡。這時我們就希望能夠隻加載目前螢幕顯示的Item的圖檔。本文引用位址:http://www.eepw.com.cn/article/201809/388380.htm

廢話不多少,直接粘貼代碼:

listView.setOnScrollListener(new OnScrollListener() {

@Override

public void onScrollStateChanged(AbsListView view, int scrollState) {

// TODO Auto-generated method stub

// 異步加載圖檔

if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {//list停止滾動時加載圖檔

pageImgLoad(_start_index, _end_index);

}

}

@Override

public void onScroll(AbsListView view, int firstVisibleItem,

int visibleItemCount, int totalItemCount) {

// TODO Auto-generated method stub

//設定目前螢幕顯示的起始index和結束index

_start_index = firstVisibleItem;

_end_index = firstVisibleItem + visibleItemCount;

if (_end_index >= totalItemCount) {

_end_index = totalItemCount - 1;

}

}

});

private void pageImgLoad(int start_index, int end_index) {

for (; start_index end_index; start_index++) {

HashMap

if (curr_item.get(Constant.NEWS_ICON_URL) != null

curr_item.get(Constant.NEWS_ICON) == null) {

loadImage(curr_item);

}

}

}