Skip to content
Agentmart
Submit a tool

android-layouts

Android layout best practices for XML/Views and Jetpack Compose.

Skill by kvithayathil

IndexedApache-2.0
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/kvithayathil-android-layouts

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Android layout best practices for XML/Views and Jetpack Compose. Covers hierarchy flattening, ConstraintLayout, merge/include, ViewStub, Compose layout phases, interop between View and Compose, adaptive layouts, and profiling tools. Use when creating, reviewing, or optimizing Android layouts in XML or Compose. Trigger on: layout, XML, ConstraintLayout, LinearLayout, RecyclerView, merge, include, ViewStub, compose layout, layout phases, LazyColumn, adaptive layout, WindowSizeClass, foldable, Layout Inspector, lint, profiling, hierarchy, double taxation, interop, AndroidView, ComposeView, modifier order, WindowInsets, contentPadding, Scaffold, CoordinatorLayout, ViewPager2, HorizontalPager, Material 3.

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/android-layouts

What's inside

Skill name
android-layouts
Description
Android layout best practices for XML/Views and Jetpack Compose. Covers hierarchy flattening, ConstraintLayout, merge/include, ViewStub, Compose layout phases, interop between View and Compose, adaptive layouts, and profiling tools. Use when creating, reviewing, or optimizing Android layouts in XML or Compose. Trigger on: layout, XML, ConstraintLayout, LinearLayout, RecyclerView, merge, include, ViewStub, compose layout, layout phases, LazyColumn, adaptive layout, WindowSizeClass, foldable, Layout Inspector, lint, profiling, hierarchy, double taxation, interop, AndroidView, ComposeView, modifier order, WindowInsets, contentPadding, Scaffold, CoordinatorLayout, ViewPager2, HorizontalPager, Material 3.
License
Apache-2.0
Metadata
author: kvithayathil · living: true · version: 1.1.0 · last-reviewed: 2026-04-24 · self-learning: true · self-updating: true · update-policy: evolve-on-evidence
Instructions
285 lines in SKILL.md · view on GitHub

Files (8)

  • SKILL.md
  • CHANGELOG.md · references/
  • COMPOSE_LAYOUTS.md · references/
  • INTEROP.md · references/
  • LESSONS_LEARNED.md · references/
  • MATERIAL_DESIGN.md · references/
  • PROFILING_TOOLS.md · references/
  • XML_LAYOUTS.md · references/

SKILL.md (first lines)

# Android Layout Best Practices

Layout performance and structure guidance for XML/View systems and Jetpack Compose.

For Compose-specific concerns (stability, recomposition, side effects, animations, modifier
extensions), use the **android-compose-ui** skill. This skill focuses on layout hierarchy,
structure, and performance.

## Reference Index

| File | Topics |
|------|--------|
| [XML_LAYOUTS.md](references/XML_LAYOUTS.md) | ConstraintLayout, merge/include, ViewStub, double taxation, RecyclerView, CoordinatorLayout, ViewPager2, WindowInsets |
| [COMPOSE_LAYOUTS.md](references/COMPOSE_LAYOUTS.md) | Layout phases, custom layouts, SubcomposeLayout, modifier order, WindowInsets, contentPadding, HorizontalPager |
| [INTEROP.md](references/INTEROP.md) | View-to-Compose migration, AndroidView, ComposeView |
| [MATERIAL_DESIGN.md](references/MATERIAL_DESIGN.md) | Scaffold, TopAppBar, NavigationBar/Rail, drawers, inset contracts |
| [PROFILING_TOOLS.md](references/PROFILING_TOOLS.md) | Layout Inspector, Lint, Perfetto, benchmarking |
| [LESSONS_LEARNED.md](references/LESSONS_LEARNED.md) | Self-learning log |
| [CHANGELOG.md](references/CHANGELOG.md) | Update history |

---

## Core Principle

**Flat hierarchies are fast hierarchies.** Every widget in the tree pays init + measure + layout +
draw cost. Each nesting level multiplies that cost across all children. The single most impactful
layout optimization is reducing depth.

---

## XML Layout Rules

### Hierarchy Depth

- Target **max 10 levels** of nesting. Profile anything deeper.
- Replace nested `LinearLayout` (especially weighted) with a single `ConstraintLayout`.
- Use `<merge>` as root tag when the layout will be included in another — eliminates one
  nesting level.
- Use `<include>` to reuse layout fragments; combine with `<merge>` for zero-overhead inclusion.

### Double Taxation

Some layout containers measure children multiple times:

| Container | Double Measure? | Why |
|-----------|-----------------|-----|
| `LinearLayout` with weights | Yes | Weight distribution requires pre-measure |
| `RelativeLayout` | Yes | Constraints may reference each other |
| `GridLayout` with weights | Yes | Same as LinearLayout weights |
| `ConstraintLayout` | No | Single-pass constraint solver |

**Rule:** If a container triggers double measurement, replace it with `ConstraintLayout` or
restructure to avoid the multi-pass trigger.

### ViewStub

Use `ViewStub` for layouts that are rarely or conditionally visible (error states, empty states,
progress indicators). `ViewStub` is a zero-dimension placeholder that inflates the real layout
only when `setVisibility(VISIBLE)` or `inflate()` is called.

```xml
<ViewStub
    android:id="@+id/stub_error"
    android:layout="@layout/error_state"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
```

```kotlin
val stub = findViewById<ViewStub>(R.id.stub_error)
stub.inflate()
```

After inflation, the `ViewStub` is replaced by the inflated view. It cannot be re-inflated.

### RecyclerView over ListView

Always use `RecyclerView`. `ListView` creates a new view for every item — no recycling.
`RecyclerView` reuses view holders and provides built-in diffing via `DiffUtil`.

### Compound Drawables

When a `TextView` has an adjacent `ImageView` (icon + text), replace both with a single
`TextView` using compound drawables:

```xml
<TextView
    android:drawableStart="@drawable/ic_search"
    android:drawablePadding="8dp"
    android:text="@string/search" />
```

This eliminates one view from the hierarchy.

### CoordinatorLayout

For coordinating scroll-dependent UI (collapsing toolbar, FAB, snackbar). See
[references/XML_LAYOUTS.md](references/XML_LAYOUTS.md) for full patterns with
`AppBarLayout`, `CollapsingToolbarLayout`, and scroll flags.

Key rule: connect `app:layout_behavior="@string/appbar_scrolling_view_behavior"` on
the scrolling sibling, and `app:layout_scrollFlags` on the AppBar children.

### ViewPager2

RecyclerView-based paging. Use `FragmentStateAdapter` for fragment pages,
`RecyclerView.Adapter` for view pages. Connect with `TabLayoutMediator` for tabs.
For new Compose code, prefer `HorizontalPager` (see Compose Layout Rules).

---

## Compose Layout Rules

### Layout Phases

Compose rendering has three phases: **Composition → Layout → Drawing**. Each phase can be
skipped independently when inputs haven't changed.

- **Composition** runs when state read during composition changes.

From kvithayathil/agent-resources, Apache-2.0.

More from kvithayathil/agent-resources

Signals

Stars
0
Forks
0
Open issues
1
Last commit (this folder)
Apr 24, 2026 (6 months ago)

From GitHub (fetched Oct 24, 2026).

Details

Version
1.1.0
License
Apache-2.0
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from kvithayathil

Cite this page

android-layouts skill. Agent Mart. https://agentmart.dev/skills/kvithayathil-android-layouts (last updated 2026-10-24)