Skip to content

The include Layout Tag

Question

When to use include

Short interview answer

Use <include> to reuse a complete layout resource in several layouts. It centralizes a common UI component while allowing supported root layout attributes to be overridden at the inclusion point.

Detailed answer

Extract a shared title bar or empty-state component into its own layout and include it where required:

<include
    layout="@layout/empty_state"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

This avoids copied XML. When overriding layout attributes on an included root, specify both width and height as required by the platform rules.

Sources