These tips are gathered from articles and Google IO videos. The items are not ordered by importance.

1. Reuse convertView

Always reuse convertView. This can improve the performance of ListView scrolling up to 50-60% percent, especially when ListView items are complex.

2. Use the Holder pattern if possible.

3. Remove realtime computation of the scrollbar thumb size

1
android:smoothScrollbar="false"

4. Cache Color Hint

Make cached color hint match the background of the ListView (or the color of the layout behind the ListView in case the ListView is transparent)

1
android:cacheColorHint="#hexcolor_equal_to_background_color"`

5. Handle optimally ListView background color

tip

By default, every Android window has a background color which comes from the theme. It’s always drawn and after that are drawn the layouts from the layout.xml files that are defined for Activities.

If a background for the ListView is explicitly specified, then we have two backgrounds that will be drawn one after the other. This is called overdraw and is unnecessary and takes more time.

If a background for the ListView is missing or is transparent, but a parent layout behind the ListView has explicitly specified a background color, then again we have two backgrounds.

To avoid the overdraw it’s better to define the background color of the app only as a theme property called windowBackground and leave the ListView without background color.

/res/values/styles.xml

1
2
3
4
5
6
<?xml version="1.0" encoding="utf-8"?>
<resources>
   <style name="AppTheme" parent="@android:style/Theme.Light">
      <item name="android:windowBackground">@color/my_background</item>
   </style>
</resources>

6. Consider using hardware acceleration

Consider if using android:hardwareAcceleration may increase ListView’s rendering performance. Read carefully here before using it.

7. Avoid wrap_content

Avoid using wrap_content for view dimensions. This includes all views and sub-views in a list item.

8. Never use ListView or GridView inside a ScrollView

9. Use stable Ids

If you have stable Ids in your dataset implement the hasStableIds() method in the adapter to return true

10. Inflate views by using the provided parent in getView

1
2
3
if(convertView == null) {
   convertView = inflater.inflate(R.layout.item_layout, parent, false);
}

11. Use Hierarchy Viewer to analyze the View tree

The tree view should be as shallow and simple as possible. Each view or viewGroup in the final ListView item has to be measured and drawn and this takes time.

info

Google IO 2010 - The world of ListView
Google IO 2013 - Android Graphics Performance