To assist you in creating the best layouts, the Android SDK provides two easy-to-use tools: hierarchyviewer and layoutopt. You can find these tools, among others, in the SDK tools directory.
The Android SDK comes with a very useful tool to view and analyze your application's layout: hierarchyviewer. As a matter of fact, Figure 8–1 and Figure 8–2 were generated using that tool. In addition to showing you the detailed layout of your application, this tool also measures how much time it takes to measure, lay out, and draw each widget, and identifies which widgets took longer to measure, lay out, and draw.
You can use hierarchyviewer as a standalone tool or directly in Eclipse with the “Hierarchy View” perspective.
The Android SDK comes with another tool that can help you with your layouts: layoutopt. This tool analyzes your layout files and can recommend changes in order to make the layout more efficient.
For example, using layoutopt on the layout from Listing 8–5 results in the following output:
The root-level <FrameLayout/> can be replaced with <merge/>
As it turns out, this is exactly what Listing 8–6 did. Running layoutopt
in Listing 8–6 did not result in any recommendation.
TIP: Use the latest version of the layoutopt tool to make sure you get the best results.
Make sure all issues reported by layoutopt are taken care of before you release your application. Unoptimized layouts can slow down your application, and it is usually quite easy to remedy such layouts.
3.141.37.10