sparkymat
sparkymat

Reputation: 10028

Poor performance with ListView when displaying large images

I have a ListView with each item being a custom layout with multiple Views (including a large image of ~445x250, a smaller image of ~40x40, etc). While scrolling, the animation is extremely choppy.

Can someone recommend how I can improve performance?

One approach I tried was to eliminate any transparency in the images being used. This did improve it slightly, though there is still a noticeable lag when before a new item scrolls into view.

Update: Here's the View heirarchy for the custom layout (for each item) - http://pastie.org/3333903

Upvotes: 2

Views: 2465

Answers (2)

Che Jami
Che Jami

Reputation: 5151

Looking at the layout provided, there are a few things that may cause performance issues:

  • Your View Hierarchy has a depth of 4. You should make your View Hierarchy as shallow as possible. Consider using a RelativeLayout/TableLayout where possible instead of nested LinearLayouts.
  • You have nested weights. Try to avoid having nested weighted views.
  • You have a lot of views for a row item. Remember the purpose of a ListView - if your rows start becoming complex, it may be a sign to look at something else to display this information.
  • A GestureOverlayView seems a bit heavy for a ListView row item. Is this necessary? Considering ListViews a scrollable by touch, having custom gestures on row items may be a bit confusing.

You can also try using android:persistentDrawingCache="scrolling" and the ViewHolder pattern to squeeze out a bit more performance.

If you download the latest version of ADT, it will also guide you in optimising your layouts.

Apart from layout optimisations, minimal work should be done in the getView method of your ListAdapter.

Additionally, you can use android:hardwareAccelerated="true" to take advantage of hardware in Android 3.0+.

Upvotes: 3

Nitesh Khosla
Nitesh Khosla

Reputation: 875

You can use the dynamic table layout instead using the List view. It will improve the performance. Dynamic table layout will adjust the large image and smaller image. It will be of help to you.

Upvotes: 0

Related Questions