Chapter 13. Optimizing the User Interface

Earlier chapters presented aids for creating dynamic and efficient layouts. The tools can make your UI good, but you’ll probably need to do some additional work to make your UI great. This chapter discusses the various tools that help you improve the efficiency of your interface code. I will show you how to use the tools to eliminate:

  • Slow or jittery redraw rates

  • A nonresponsive, poorly performing UI

Introduction to UI Performance

In addition to the content covered in Chapter 11, there are a few concepts relating to how Android builds user interfaces that are important to understand.

How Android Draws Views, and How It Affects UI Performance

When an activity gets started, it asks the framework to draw its UI from its layout definitions. The UI is drawn by walking the View tree and rendering each ViewGroup. Then each ViewGroup requests each of its children to be drawn until all Views in the hierarchy have been rendered. The tree is traversed in order, which means that parents are drawn before their children, with the final order determined by where they appear in the tree.

Two-pass layout

The runtime draws the layout through a two-pass process via the View tree, visualized in Figure 13-1. For each View rendering, the system must perform two operations: a measure pass and a layout pass. The measure pass collects dimension specifications and the layout pass positions the Views on the screen.

Measure pass

This pass traverses the entire View tree to determine ...

Get Android Developer Tools Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.