Is it possible to define a ‘virtual size’ for ListView in Android and thereby have it allocate more views and get these earlier before they are visible on the screen? For example, if my listview is 400px high, and my items are 100px high, listview will allocate ~5 item views and reuse these as the list scrolls. Is it possible to define a virtual head and tail size for listview (off-screen) such that items in this space are getView()’ed?
My problem: I have a list with items that each contain a photo read async from storage (sd-card). This entails a certain latency for when the item is ready. When I fling the list, a few top/bottom (flinging down/up) number of new items are in the process of being loaded. The system can keep up => throughput is ok, but the read latency is the problem. If listview could have some extra off-screen items that were scrolled in, this would probably resolve my problem.
Any inputs?
I had a similar problem (loading images into a GridView asynchronously) that I solved by overriding
onMeasure()in a GridView subclass. ListView has the same method. My code looked something like this:As I understand it, this will make the view think that it is larger than it actually is on screen, causing it keep more offscreen views alive rather than recycling them. You could change the 500 to whatever size will preload enough images for your application.
Unfortunately, I’ve found that this doesn’t work when scrolling upwards (only downwards). I haven’t been able to figure out why this is.