天天看点

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);

}

}

}