优化的Andr​​oid ListView的getView [英] optimize android listview's getView

查看:167
本文介绍了优化的Andr​​oid ListView的getView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法,我可以美元的Andr​​oid的ListView p $ P加载了几个看法?

I am wondering if there's a way I can pre-load a couple of views in Android ListView?

例如,默认情况下,当一个列表视图项目滚动在屏幕之外,它会成为一个转换视图,将重新装饰成屏幕上的下一个视图。我的问题是,每一个列表视图项是从内存中加载pretty大尺寸图像,如果它开始加载正确的之前,它是将要呈现涨它就会卡住滚动。

For example, by default, when a listview items scrolls out of the screen, it will become a convert view and will be re-decorated as the next view on screen. My problem is, each listview item is loading a pretty large size image from memory, and it will stuck scrolling if it begin load right before it is gonna show up.

我在想,如果有我可以指定加载意见的门槛,例如一种方式,以preLOAD 3次,而不是1?

I was wondering if there's a way I can specify the threshold of loading views, for example, to preload 3 views rather than 1?

感谢您

推荐答案

有是有点不同的方式为这个:

There is a bit different approach for this:

首先,从适配器 getView删除您装载操作()。这种方法应该是尽可能精简版。装载第一批图像的背景和它传递给适配器。 (店列表,例如)

First, remove your loading actions from adapter's getView(). This method should be as lite as possible. Load a first batch of images in background and pass it to adapter. (store in List, for example)

二。设置 AbsListView.OnScrollListener 您的ListView,覆盖 onScroll()并计算已滚动查看用户的数量:诠释计数= firstVisibleItem + visibleItemCount; 。如果这INT超过您加载图像的数量,开始显示进度条,并在后台线程加载图片,将它们提供给您的适配器(添加到您的列表)。呼叫 notifyDataSetChanged()上载后,您的适配器是完整的,你做。

Second. Set AbsListView.OnScrollListener on your listView, override onScroll() and calculate the amount of views user has scrolled: int count = firstVisibleItem + visibleItemCount;. If this int exceeds the number of images you loaded, start showing a progress bar and load your images in background thread, supplying them to your adapter (add to your List). Call notifyDataSetChanged() on your adapter after load is complete and you are done.

你应该可以加载尽可能多的项目。

You can load as many items as you should.

这篇关于优化的Andr​​oid ListView的getView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆