Background information:
I’m working on a small app for myself and a few friends, and it contains a few ListViews with items based on custom XML layouts. The layouts are somewhat heavy – a few ImageViews, TextViews, a LinearLayout and a RelativeLayout – so I started thinking about performance. I’m not personally experiencing any performance issues, but I know that some of my friends, who’ll be using the app, don’t have high-end phones and that they might have issues with these layouts.
I remember watching a video presentation regarding performance in Android, and I recall Romain Guy mentioning something about custom Views being better for performance than constantly inflating custom XML layouts. I believe the context was the early development of the Gmail application (around Android 1.5, I believe), where each item of the Listview was rather complex.
It’s probably worth pointing out that I’m reusing Views in my application, and that I’m using the ViewHolder principle as recommended by Google.
My question: Is it better for performance to use custom Views or is it OK to inflate custom XML layouts?
As always, then answer is “it depends” – inflating view from XML imposes some performance penalty ( parsing overhead ) over plain creation in code, but also provides greater flexibility. You should definitely reuse views whenever possible ( especially in larger lists) – it improves scrolling performance dramatically