We have an data-driven activity which constructs a large set (typically, up to 100) of Button-like components and places them in a Scrollable. Each of the buttons is inflated from a resource and are based on a RelativeLayout. The button has two text views, two image views - both from resources - and has a background of a 9-patch.
The size, position, text, and configuration of the image views are all driven from a database query.
Unfortunately, this is taking between 2-3 seconds to layout on an HTC Desire, 3-5 seconds on an HTC San Francisco or HTC Sapphire.
Once the initial layout is done, the view performs beautifully.
We have tried a number of strategies which made no difference:
- time the database query - this was not a significant part of the delay.
- cache the buttons, to reduce the amount of layout inflation.
- constructing a subtree of views outside of the “live” view hierarchy, then connecting it when complete.
- doing the same on another thread, but connecting the subtree to the activity on the UI thread.
We have an indefinite progress indicator (spinner/throbber) which spins while the query runs on another thread, but then freezes when layout gets going.
So, my question are these:
- how can I make the layout of the views seem more responsive or
- how can I avoid the thobber locking up while layout occurs
Thanks.
Edit
The scroller is set to scroll horizontally and vertically. So we have a grid which the screen is a viewport on.
This makes using the built in ListView (at first glance) unsuitable for the task.