December 19, 2014

Layout Problems Redux: Hierarchy Viewer

In the previous Building ‘Droids post, we went through an exercise of figuring out what was going wrong with a RelativeLayout used as rows in a ListView. This exercise used “retro” diagnostic techniques, such as changing background colors, to see what’s going on.

Two commenters, including Romain Guy from the Android team, pointed out the Hierarchy Viewer tool that has been added to the 0.9 SDK. So, today, let’s see what this tool is all about and how it can help you make sense of your layouts as they are used.

To use the Hierarchy Viewer, you first need to fire up your emulator, install your application, launch your activity, and navigate to spot you wish to examine. For today’s demonstration, we’ll use a trivial activity, whose layout is shown below:

[sourcecode language=”xml”]

apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">