How-To: Debug Android UI

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
  • Layoutopt

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.

  1. Connect your device or launch an emulator
  2. From a terminal, launch hierarchyviewer from your SDK /tools directory.
  3. 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.
  4. 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.

  1. From a terminal, launch layoutopt from your SDK /tools directory.
  2. The argument is a space- delimited list of resources you want to analyze, either non-compiled resource xml files or directories of such files.

Leave a Reply


captcha *

This site uses Akismet to reduce spam. Learn how your comment data is processed.