The Layout Inspector in Android Studio allows you to debug the layout of your app by showing a view hierarchy and allowing you to inspect the properties of each view. With the Layout Inspector, you can compare your app layout with design mockups, display a magnified or 3D view of your app, and examine details of its layout at runtime. This is especially useful when your layout is built at runtime rather than entirely in XML and the layout is behaving unexpectedly.
Layout Validation allows you to simultaneously preview layouts on different devices and display configurations, including variable font sizes or user languages, making it easy to test for a variety of common layout problems.
To open the Layout Inspector, run your app on a connected device or emulator, and then select Tools > Layout Inspector. If you switch among multiple devices or projects, the Layout Inspector automatically connects to the debuggable processes running in the foreground of the connected device.
Figure 1. Layout Inspector snapshot for the Sunflower sample app. The Layout Inspector displays the following from left to right: Component Tree, Layout Display, and Attributes.
- Component Tree: The hierarchy of views in the layout.
- Layout Display: Rendering of the app's layout as it appears on your device or emulator, with layout bounds shown for each view.
- Attributes: The layout attributes for the selected view. Layout Inspector requires an activity restart to access the attributes. For more information, see Activity restart.
To learn about the Layout Editor, see Introduction to the Layout Editor.
The Layout Display renders your app's layout as it appears on your device or emulator, with layout bounds shown for each view. You can click on each component to inspect it.
The Live Layout Inspector provides complete, real-time insights into your app’s UI while it’s deployed to a device or emulator running API level 29 or higher.
To enable the Live Layout Inspector, select the Live Updates option from the Layout Inspector toolbar.
The Live Layout Inspector includes a dynamic layout hierarchy, updating the Component Tree and Layout Display as views on the device change.
Select or isolate a view
A view usually draws something the user can see and interact with. The Component Tree shows your app's hierarchy in real time with each view component, which helps you debug your app's layout because you can visualize the elements within your app and the values associated with them.
To select a view, click it in the Component Tree or the Layout Display. All of the layout attributes for the selected view appear in the Attributes panel.
If your layout includes overlapping views, you can select a view that is not in front by clicking it in the Component Tree or by rotating the layout.
To work with complex layouts, you can isolate individual views so that only a subset of the layout is shown in the Component Tree and rendered in the Layout Display.
Figure 2. To isolate a view, right-click the view in the Component Tree and select Show Only Subtree or Show Only Parents.
To return to the full view, right-click the view and select Show All.
Hide layout borders and view labels
To hide the bounding box or view labels for a layout element, click View Options at the top of the Layout Display and toggle Show Borders or Show View Label.
Figure 3. To hide layout borders and view labels, click on the second View Options in the Layout Inspector toolbar.
The Layout Display features an advanced 3D visualization of your app’s view hierarchy at runtime. To use this feature, in the Live Layout Inspector window, click on the 3D Mode button and rotate it by dragging the mouse.
Figure 4. Rotated 3D view of a Layout.
Figure 5. To expand or contract the layers of the Layout, use the Layer Spacing slider.
Compare app layout to a reference image overlay
To compare your app layout with a reference image, such as a UI mockup, you can load a bitmap image overlay in the Layout Inspector.
- To load an overlay, select the Load Overlay option from the Layout Inspector toolbar. The overlay is scaled to fit the layout.
- To adjust the transparency of the overlay, use the Overlay Alpha slider.
- To remove the overlay, click Clear Overlay .
Capture layout hierarchy snapshots
Layout Inspector allows you to save snapshots of your running app’s layout hierarchy, so that you can easily share them with others or refer to them later.
Snapshots capture the data you would typically see when using the Layout Inspector, including a detailed 3D rendering of your layout, the component tree of your View, Compose, or hybrid layout, and detailed attributes for each component of your UI. To save a snapshot, do the following:
- Open the layout inspector.
- The Layout Inspector should connect to your app process automatically. If not, select the app process from the dropdown menu.
- When you want to capture a snapshot, click Export snapshot from the Layout Inspector toolbar.
- In the system dialog that appears, specify the name and location you want to
save your snapshot. Make sure to save the file with a
You can then load a Layout Inspector snapshot by selecting File > Open from
the main menu bar, and opening a
Figure 6. Taking a snapshot in the Layout Inspector.
Layout Inspector lets you inspect a Compose layout inside a running app in an emulator or physical device. You can use the Layout Inspector to check how often a composable is recomposed or skipped, which can help identify issues with your app. For example, some coding errors might force your UI to recompose excessively, which can cause poor performance. Some coding errors can prevent your UI from recomposing and, therefore, preventing your UI changes from showing up on the screen.
Learn more about Layout Inspector for Compose
Avoiding activity restarts
Layout Inspector requires one of the following global settings to function properly. If you don't specify a global setting, Layout Inspector automatically sets one.
adb shell settings put global debug_view_attributes_application_package <processname>
This option generates extra information for inspection of the specified process.
adb shell settings put global debug_view_attributes 1
This option generates extra information for inspection on all of the processes on the device.
Changing a global setting may cause an activity restart. To avoid an activity restart, you can either change the settings in Android Studio or change the Developer Options in your device's settings.
To enable automatic refresh in Android Studio, open the Run/Debug Configurations by selecting Run > Edit Configurations from the menu. Then, navigate to the Miscellaneous tab and check the Connect to Layout Inspector without restarting activity box under Layout Inspector Options.
Figure 11. Enable automatic refresh from the Run/Debug Configurations.
Alternatively, enable your device's developer options, and then turn on Enable view attribute inspection from the device's developer settings.
Layout Validation is a visual tool for simultaneously previewing layouts for different devices and display configurations, helping you catch problems in your layouts earlier in the process. To access this feature, click on the Layout Validation tab in the top-right corner of the IDE window:
Figure 12. Layout Validation tab.
To switch between the available configuration sets, select one of the following from the Reference Devices dropdown at the top of the Layout Validation window:
- Reference Devices
- Color Blind
- Font Sizes
Figure 13. Reference Devices dropdown menu option.
Reference devices are a set of devices that we recommend you test against. They include phone, foldable, tablet, and desktop interfaces. You should preview how your layout appears on this set of reference devices:
Figure 14. Reference device previews in the Layout Validation tool.
To customize a display configuration to preview, choose from a variety of settings including language, device, or screen orientation:
Figure 15. Configure a custom display in the Layout Validation tool.
To help make your app more accessible for users who are color blind, validate your layout with simulations of common types of color blindness:
Figure 16. Color blindness simulation previews in the Layout Validation tool.
Validate your layouts at various font sizes, and improve your app's accessibility for visually impaired users by testing your layouts with larger fonts:
Figure 17. Variable font size previews in the Layout Validation tool.