When debugging an Android application it’s important to look at the structure of the UI. There are tools that help you visualize the UI. Inside this article I will be explaining two tools:
- Hierarchy Viewer
The Hierarchy Viewer application provides a visual representation of the layout’s View hierarchy (the Layout View) and a magnified inspector of the display (the Pixel Perfect View). So lets run the tool.
- Connect your device or launch an emulator
- From a terminal, launch hierarchyviewer from your SDK /tools directory.
- In the window that opens, you’ll see a list of Devices. When a device is selected, a list of currently active Windows is displayed on the right. The focused window is the window currently in the foreground, and also the default window loaded if you do not select another.
- Select the window that you’d like to inspect and click Load View Hierarchy. The Layout View will be loaded. You can then load the Pixel Perfect View by clicking the second icon at the bottom-left of the window.
Layoutopt is a command line tool which can analyse a layout resource file and tell you what is not required. So lets run the tool.
- From a terminal, launch layoutopt from your SDK /tools directory.
- The argument is a space- delimited list of resources you want to analyze, either non-compiled resource xml files or directories of such files.