Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The solution is to implement a more intelligent method of when to fetch thumbnails - it is pointless fetching thumbnails while the user is flinging through the list. Essentially you want something like that implemented in Romain Guy's <a href="http://code.google.com/p/shelves/" rel="nofollow noreferrer">Shelves</a> application.</p> <p>To get the most responsive Gallery you'll need to implement some form of in-memory cache and do the following:</p> <ul> <li>Only set an image if it exists in the in-memory cache from your <code>getView</code>. Set a flag indicating whether the image was set or whether a download is required. You could also maintain a memory in a cache on the SD card and internal memory, and if a fling is not currently ongoing then show a low res (<code>inSampleSize</code> set to 16 or 8) version which will be visible when just scrolling through - the high res version will load when the user lets go and settles on an image.</li> <li>Add an <code>OnItemSelectedListener</code> (and make sure to call <code>setCallbackDuringFling(false)</code> when initializing) that downloads new thumbnails for all the visible items that require a download <em>only if the users finger is up</em> (you can use <code>getFirstVisiblePosition</code> and <code>getLastVisiblePosition</code> to find the range of views visible)</li> <li>Also when the user lifts their finger check to see 1. if the selected position changed since the user put their finger down and if so 2. whether a download was initiated due to your <code>OnItemSelectedListener</code> - if it wasn't then initiate one. This is to catch the case where no flinging occurs, and thus <code>OnItemSelected</code> never does anything because it is always called with the finger down in this situation. I'd use a Handler to delay starting the downloading by the animation time of your gallery (make sure to clear any delayed messages posted to this handler whenever <code>onItemSelected</code> is called or when you get an <code>ACTION_DOWN</code> event.</li> <li>After an image is downloaded check if any visible views requested this image then and update those views</li> </ul> <p>Also be aware that the default Gallery component does not properly implement View recycling (it assumes each position in the adapter has a unique view, and also clears the recycler of these items when they go offscreen making it pretty pointless). <strong>Edit:</strong> on more looking it isn't pointless - but it's not a recycler in terms of next/previous views, rather it serves to avoid having to call <code>getView</code> for the current views during layout changes. </p> <p>This means the <code>convertView</code> parameter passed to your <code>getView</code> method will more often that not be null, meaning you'll be inflating a lot of views (which is expensive) - see my answer to <a href="https://stackoverflow.com/questions/5789879/android-does-a-replacement-for-gallery-widget-with-view-recycling-exist">Does a replacement for Gallery with View recycling exist?</a> for some hints on that. (PS: I have since modified that code - I would use a different recycle bin for layout phases and scroll phases, in the layout phase place and retrieve the views in the layout recycle bin according to their position, and DO NOT call getView if the view you get from the bin is non-null since it will be exactly the same view; also clear the layout recycle bin after the layout phase -- this makes things a bit more snappier)</p> <p>PS: Also be very careful with what you do in <code>OnItemSelected</code> - namely unless it's in the places mentioned above then try to do as little as possible. For instance I was setting some text in a <code>TextView</code> above my Gallery in <code>OnItemSelected</code>. Just moving this call into the same points as where I updated thumbnails made a noticable difference.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload