The Layout Inspector in Android Studio allows you to inspect your app's view hierarchy at runtime from within the Android Studio IDE. This is particularly useful when your layout is built at runtime rather than entirely in XML and the layout is behaving unexpectedly.
Open the Layout Inspector as follows:
- Run your app on a connected device or emulator.
- Click Tools > Android > Layout Inspector.
-
In the Choose Process dialog that appears, select the app process you want to inspect and click OK.
Figure 1. The Choose Process dialog
By default, the Choose Process dialog lists only the process for the project currently opened in Android Studio—and it must be running on the device. If you want to inspect a different app that's on the device, check Show all processes. If you're using a rooted device or an emulator without Google Play store, then you'll see all running apps. Otherwise, you'll see only running apps that are debuggable.
The Layout Inspector captures a snapshot, saves it as a .li file, and opens
it. As shown in figure 2, the Layout Inspector displays the following:
- View Tree: The hierarchy of views in the layout.
- Screenshot: The device screenshot with visible boundaries for each view.
- Properties Table: The layout properties for the selected view.
Figure 2. The Layout Inspector
You can click a view in the View Tree to select the same view in the screenshot, and vice versa. All the layout attributes for the view appear in the Properties Table.
If your layout includes overlapping views, then by default, only the view in front is clickable in the screenshot. To make the view behind clickable in the screenshot: Right-click the in-front view in the View Tree and uncheck Show in preview. It doesn't make the view content disappear; it only makes the clickable boundaries in the screenshot disappear so that you can instead click the views behind it.
If the layout on the device changes, the Layout Inspector does not update. You
must create a new snapshot by again clicking Tools > Android > Layout
Inspector. Each snapshot is saved in a separate .li file in
project-name/captures/.
Figure 3. Layout Inspector snapshots (.li files)
in the Project window