2

I am having this strange issue with listView and cacheColorHint..

I have the background of the activity set to a gradient..

When I set the android:cacheColorHint="#00000000" the scrolling becomes laggy, else it is super smooth.

I also tried programatically setting it...same laggy scrolling(dumb thing to think that it'd work )

When I don't set it...I have the flickering when I scroll that is why I set the cacheHintColor in the first place.....

It is the same problem as seen in this question although it seems it hasn't been solved..

ListView with getView() Over-Ridden Slow Due To Constant GC?

I've seen many applications which have smooth scrolling in-spite of having all sorts of backgrounds...so pease suggest a workaround or a fix please...

Additional details: App is a twitter client uses lists in a ListFragment. Each list item contains an image loaded from twitter...I'm using an opensource image loader class which works well(cant quite remember which one)...but since scrolling works well if cacheHintColor not set..hence I can rule out that the problem is with the image caching...

Community
  • 1
  • 1
avatsav
  • 1,208
  • 1
  • 8
  • 16
  • My advise is to firstly use traceview and check why exactly your list is so slow. Additionally make sure you are reusing views passed to you in the getView() method of your adapter. Also use the view holder pattern..Iam sure we could help you more of you post some of your code.. – Renard Mar 24 '12 at 21:41
  • I was able to solve the issue by reducing the size of the image view..it was stretching a much smaller image to fill the image view...when i reduced it it worked perfectly...also for the list view i set the scrollingCache to true...any idea why this happened..?? – avatsav Mar 26 '12 at 05:13
  • 1
    Your imageviews where scaling the bitmaps in software on each and every frame. So thats always going to be costly in terms of performance. Also when you use the scollingCache what happens internally is that the system renders each child view into an offscreen bitmap first so that scrolling can be done by simply translating these bitmaps. This optimization technique is the reason for the flickering you experienced. – Renard Mar 26 '12 at 08:04
  • thanks for the explanation...does this also happen when a large image is scaled down to the size of the ImageView..?? – avatsav Mar 26 '12 at 09:40
  • 1
    Yes. When possible you should avoid scaling in the imageview altogether. Have a look at [ImageView.ScaleType](http://developer.android.com/reference/android/widget/ImageView.ScaleType.html). If your bitmaps are application resources then simply package your bitmaps with the final and correct sizes. Otherwise you can scale bitmaps at runtime by using Bitmap.createScaledBitmap() – Renard Mar 26 '12 at 10:54
  • Ah...really nice tips...will keep in mind...thanks a lot Renard..really appreciate it.. :) – avatsav Mar 26 '12 at 12:10

1 Answers1

2

Perhaps it's slow because you're setting a transparent cache color hint which is forcing alpha compositing during scrolling. If your background is a solid color try setting a hint with full alpha, e.g. 0xff000000

Also, I imagine turning on scrollingCache will cache the overscrolled parts of the ListView, which would mean less drawing has to be done, but at the expense of more memory usage.

nmr
  • 16,625
  • 10
  • 53
  • 67