home / skills / hoangnguyen0403 / agent-skills-standard / xml-views

xml-views skill

/skills/android/xml-views

This skill enforces Android XML View standards by advocating ViewBinding, RecyclerView with ListAdapter, and efficient Layouts to boost app reliability.

npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill xml-views

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
1.1 KB
---
name: Android XML Views
description: Standards for ViewBinding, RecyclerView, and XML Layouts
metadata:
  labels: [android, xml, views, viewbinding]
  triggers:
    files: ['layout/*.xml', '**/*Binding.java', '**/*Binding.kt']
    keywords: ['ViewBinding', 'ConstraintLayout', 'RecyclerView']
---

# Android XML Views Standards

## **Priority: P1**

## Implementation Guidelines

### ViewBinding

- **Standard**: Use ViewBinding for all XML layouts.
- **Synthetics**: `kotlin-android-extensions` is Dead. Remove it.
- **KAPT**: Avoid DataBinding unless strictly necessary (impacts build speed).

### RecyclerView

- **Adapter**: Always inherit `ListAdapter` (wraps AsyncListDiffer).
- **Updates**: Provide a proper `DiffUtil.ItemCallback`. NEVER call `notifyDataSetChanged()`.

### Layouts

- **ConstraintLayout**: Use for complex flat hierarchies.
- **Performance**: Avoid deep nesting (LinearLayout inside LinearLayout).

## Anti-Patterns

- **findViewById**: `**Deprecated**: Use ViewBinding.`
- **Synthetics**: `**Deprecated**: Remove import kotlinx.android.synthetic.*.`

## References

- [ViewBinding & Adapter](references/implementation.md)

Overview

This skill documents standards for Android XML views, focusing on ViewBinding, RecyclerView usage, and XML layout best practices. It defines clear rules to improve runtime performance, reduce build-time friction, and enforce maintainable UI code. The guidance targets Kotlin Android projects and complements adapters, diffing, and layout choices.

How this skill works

The skill inspects UI layer patterns and recommends replacing deprecated APIs and anti-patterns with modern alternatives. It enforces ViewBinding for all XML layouts, prescribes ListAdapter with DiffUtil for RecyclerView adapters, and promotes ConstraintLayout for flat, performant view hierarchies. It also flags legacy synthetics and findViewById usages for removal.

When to use it

  • Onboarding new Android UI codebases to a shared standard.
  • Code reviews that touch XML layouts, adapters, or view lookups.
  • Refactoring efforts to remove deprecated view access patterns.
  • CI linters or pre-commit checks to enforce UI best practices.
  • When migrating from older libraries or simplifying build times.

Best practices

  • Enable ViewBinding and use the generated binding classes for all fragments and activities.
  • Prefer ListAdapter with a proper DiffUtil.ItemCallback instead of manual notify calls.
  • Never call notifyDataSetChanged(); use Differential updates via AsyncListDiffer.
  • Avoid kotlin-android-extensions (synthetics) and remove related imports.
  • Use ConstraintLayout to keep hierarchies flat and avoid deep nested LinearLayouts.
  • Avoid DataBinding unless required for expressiveness; it can increase build time.

Example use cases

  • Refactor an activity that still uses findViewById to use ViewBinding and remove manual view lookups.
  • Replace a RecyclerView.Adapter that calls notifyDataSetChanged() with a ListAdapter and DiffUtil implementation.
  • Audit layouts to collapse nested layouts into a single ConstraintLayout for performance gains.
  • Add a lint rule or CI check to detect kotlin-android-extensions imports and flag them for removal.
  • Choose ViewBinding over DataBinding to speed up incremental builds while keeping type-safe access.

FAQ

Why avoid kotlin-android-extensions synthetics?

Synthetics are deprecated, break module boundaries, and can cause obscure runtime issues; ViewBinding is safer and type-safe.

When is DataBinding acceptable?

Use DataBinding only when you need two-way binding or complex expression logic in XML and the benefits outweigh slower build times.