Wednesday, October 28, 2009

Android UI Tricks and Tips for Performance

  1. Pre-scale your views
  2. Use Adaptors
  3. don't use invalidate() - use a specific Rect or region. Use Developer Settings, show screen redraw tools on the device/emulator
  4. look at the view hierarchy in the emulator --- avoid deep trees --- wide trees are preferred.
  5. emulator shows the rendering time, layout time, etc
  6. Compound drawables - collapse views/levels in the view hierarchy (e.g. images adjacent to text)
  7. ViewStub -- hidden portions- keeps UI views to a minimum (review the Android source code for examples)
  8. use the tag instead of a dummy frame or layout node/tag --- again, always avoid hierarchy levels, use the tag to be the root in xml
  9. Use RelativeLayouts instead of linear layouts
  10. Try using Custom View and Layout children from the Base classes --- rather than expand the hierarchy by nesting standard layouts
  11. Standard java performance stuff --- watch GC, allocations (Allocation Tracker tool) String, understand Soft,Weak References

No comments: