0

I have a listview showing rows containing images from the web.

once a row needs to be drawn, in Adapter.getView(...), I download the image in the background and set it to the ImageView in the UI thread. This means that the bitmap is being set into the ImageView in a delayed manner.

I tried the delayed setImage...() with simple drawable resources and the result was the same.

I observed that setting a resource in a delayed mannger, causes the whole list to be redrawn starting with position 0, which is not even shown - up to the shown position. The obvious problem is that the list scroll is slow and jumpy and not smooth.

I want to be extra careful here: This happens while scrolling a bit. The new seen items do get drawn as part of the regular makeAndAddView. But, immediately after that all the rows leading up to the seen rows are being painted as part of measureHeightOfChildren.

Setting the image immediately and not delayed does not cause the onMeasure to be invoked.

So how do I prevent the repaint of all the list and why is the behavior different between the immediate setImage and the delayed?

AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277
  • Oh, and I tested it on several Android device versions: 4.1.2, 4.3 and 4.4.4. – AlikElzin-kilaka Oct 14 '14 at 12:38
  • Oh, look what I found. I found a todo in Android's code to measure, starting from the first visible position and not 0. Quote: `// TODO: after first layout we should maybe start at the first visible position, not 0`. See for yourself: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4.4_r1/android/widget/ListView.java#ListView.onMeasure%28int%2Cint%29 – AlikElzin-kilaka Oct 14 '14 at 12:43
  • Anyhow, a question still remains: why is the measurement requested in the immediate `setImage` scenario and not the delayed scenario? – AlikElzin-kilaka Oct 14 '14 at 12:46
  • I wrote some logic in the adapter to ignore unseen positions but the rendering is still very slow. – AlikElzin-kilaka Oct 14 '14 at 14:29
  • The following answer prevent the repainting of everything: http://stackoverflow.com/a/2639159/435605 – AlikElzin-kilaka Nov 21 '14 at 04:29

1 Answers1

0

The delayed vs. un-delayed setImage...() question still remains unsolved.

I did manage to prevent the measurement on the delayed scenario by setting the listview's layout_height to match_parent instead of wrap_content.

AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277