Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
new-silvermoon avatar

Xml To Compose Migration

  • 359 installs
  • 910 repo stars
  • Updated July 27, 2026
  • new-silvermoon/awesome-android-agent-skills

xml-to-compose-migration is an Android agent skill that converts legacy XML layouts and View widgets to idiomatic Jetpack Compose for developers modernizing View-system UI while preserving accessibility and navigation be

About

xml-to-compose-migration is an agent skill in new-silvermoon/awesome-android-agent-skills that systematically converts Android XML layouts to idiomatic Jetpack Compose. The five-step workflow analyzes root layouts (ConstraintLayout, LinearLayout, FrameLayout), maps 11 container layouts and 18 common widgets to Compose equivalents, migrates LiveData observation to collectAsStateWithLifecycle, and supports incremental interop via ComposeView and AndroidView. Attribute mapping covers fillMaxWidth, weight, padding, visibility, clickable, and semantics contentDescription. Developers reach for xml-to-compose-migration when refactoring Fragment XML screens to Compose, replacing RecyclerView adapters with LazyColumn, or planning incremental migration with ComposeView embedding while preserving accessibility and configuration-change state.

  • Guides Jetpack Compose migration from XML
  • Targets Android UI modernization workflows
  • Supports agent-assisted screen refactors
  • Covers layout parity and component mapping
  • Fits mobile app maintenance and upgrades

Xml To Compose Migration by the numbers

  • 359 all-time installs (skills.sh)
  • +10 installs in the week ending Aug 4, 2026 (Skillselion tracking)
  • Ranked #352 of 1,039 Mobile Development skills by installs in the Skillselion catalog
  • Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill xml-to-compose-migration

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs359
repo stars910
Last updatedJuly 27, 2026
Repositorynew-silvermoon/awesome-android-agent-skills

How do you migrate Android XML layouts to Compose?

Migrate legacy Android XML layouts and views to Jetpack Compose while preserving behavior, accessibility, and navigation patterns during agent-assisted refactors.

Who is it for?

Android developers refactoring legacy View-system screens to Jetpack Compose who need layout mapping guidance, state migration patterns, and incremental ComposeView interop.

Skip if: Skip xml-to-compose-migration when building greenfield Compose apps with no XML legacy, or when the task is backend/API work unrelated to Android UI layout conversion.

When should I use this skill?

User asks to migrate XML to Compose, convert ConstraintLayout screens, replace RecyclerView with LazyColumn, or modernize View-system UI.

What you get

Idiomatic Compose Composables, removed ViewBinding/DataBinding, LazyColumn list replacements, and accessibility-preserving UI code with preview annotations.

  • Compose Composable source files
  • Layout mapping refactor plan
  • Migration checklist completion

By the numbers

  • Maps 11 XML container layouts to Compose equivalents
  • Maps 18 common XML widgets to Compose components
  • 10-item migration checklist in SKILL.md

Files

SKILL.mdMarkdownGitHub ↗

XML to Compose Migration

Overview

Systematically convert Android XML layouts to idiomatic Jetpack Compose, preserving functionality while embracing Compose patterns. This skill covers layout mapping, state migration, and incremental adoption strategies.

Workflow

1. Analyze the XML Layout

  • Identify the root layout type (ConstraintLayout, LinearLayout, FrameLayout, etc.).
  • List all View widgets and their key attributes.
  • Map data binding expressions (@{}) or view binding references.
  • Identify custom views that need special handling.
  • Note any include, merge, or ViewStub usage.

2. Plan the Migration

  • Decide: Full rewrite or incremental migration (using ComposeView/AndroidView).
  • Identify state sources (ViewModel, LiveData, savedInstanceState).
  • List reusable components to extract as separate Composables.
  • Plan navigation integration if using Navigation component.

3. Convert Layouts

Apply the layout mapping table below to convert each View to its Compose equivalent.

4. Migrate State

  • Convert LiveData observation to StateFlow collection or observeAsState().
  • Replace findViewById / ViewBinding with Compose state.
  • Convert click listeners to lambda parameters.

5. Test and Verify

  • Compare visual output between XML and Compose versions.
  • Test accessibility (content descriptions, touch targets).
  • Verify state preservation across configuration changes.

---

Layout Mapping Reference

Container Layouts

XML LayoutCompose EquivalentNotes
LinearLayout (vertical)ColumnUse Arrangement and Alignment
LinearLayout (horizontal)RowUse Arrangement and Alignment
FrameLayoutBoxChildren stack on top of each other
ConstraintLayoutConstraintLayout (Compose)Use createRefs() and constrainAs
RelativeLayoutBox or ConstraintLayoutPrefer Box for simple overlap
ScrollViewColumn + Modifier.verticalScroll()Or use LazyColumn for lists
HorizontalScrollViewRow + Modifier.horizontalScroll()Or use LazyRow for lists
RecyclerViewLazyColumn / LazyRow / LazyGridMost common migration
ViewPager2HorizontalPagerFrom accompanist or Compose Foundation
CoordinatorLayoutCustom + ScaffoldUse TopAppBar with scroll behavior
NestedScrollViewColumn + Modifier.verticalScroll()Prefer Lazy variants

Common Widgets

XML WidgetCompose EquivalentNotes
TextViewTextUse styleTextStyle
EditTextTextField / OutlinedTextFieldRequires state hoisting
ButtonButtonUse onClick lambda
ImageViewImageUse painterResource() or Coil
ImageButtonIconButtonUse Icon inside
CheckBoxCheckboxRequires checked + onCheckedChange
RadioButtonRadioButtonUse with Row for groups
SwitchSwitchRequires state hoisting
ProgressBar (circular)CircularProgressIndicator
ProgressBar (horizontal)LinearProgressIndicator
SeekBarSliderRequires state hoisting
SpinnerDropdownMenu + ExposedDropdownMenuBoxMore complex pattern
CardViewCardFrom Material 3
ToolbarTopAppBarUse inside Scaffold
BottomNavigationViewNavigationBarMaterial 3
FloatingActionButtonFloatingActionButtonUse inside Scaffold
DividerHorizontalDivider / VerticalDivider
SpaceSpacerUse Modifier.size()

Attribute Mapping

XML AttributeCompose Modifier/Property
android:layout_width="match_parent"Modifier.fillMaxWidth()
android:layout_height="match_parent"Modifier.fillMaxHeight()
android:layout_width="wrap_content"Modifier.wrapContentWidth() (usually implicit)
android:layout_weightModifier.weight(1f)
android:paddingModifier.padding()
android:layout_marginModifier.padding() on parent, or use Arrangement.spacedBy()
android:backgroundModifier.background()
android:visibility="gone"Conditional composition (don't emit)
android:visibility="invisible"Modifier.alpha(0f) (keeps space)
android:clickableModifier.clickable { }
android:contentDescriptionModifier.semantics { contentDescription = "" }
android:elevationModifier.shadow() or component's elevation param
android:alphaModifier.alpha()
android:rotationModifier.rotate()
android:scaleX/YModifier.scale()
android:gravityAlignment parameter or Arrangement
android:layout_gravityModifier.align()

---

Common Patterns

LinearLayout with Weights

<!-- XML -->
<LinearLayout android:orientation="horizontal">
    <View android:layout_weight="1" />
    <View android:layout_weight="2" />
</LinearLayout>
// Compose
Row(modifier = Modifier.fillMaxWidth()) {
    Box(modifier = Modifier.weight(1f))
    Box(modifier = Modifier.weight(2f))
}

RecyclerView to LazyColumn

<!-- XML -->
<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
// Compose
LazyColumn(modifier = Modifier.fillMaxSize()) {
    items(items, key = { it.id }) { item ->
        ItemRow(item = item, onClick = { onItemClick(item) })
    }
}

EditText with Two-Way Binding

<!-- XML with Data Binding -->
<EditText
    android:text="@={viewModel.username}"
    android:hint="@string/username_hint" />
// Compose
val username by viewModel.username.collectAsState()

OutlinedTextField(
    value = username,
    onValueChange = { viewModel.updateUsername(it) },
    label = { Text(stringResource(R.string.username_hint)) },
    modifier = Modifier.fillMaxWidth()
)

ConstraintLayout Migration

<!-- XML -->
<androidx.constraintlayout.widget.ConstraintLayout>
    <TextView
        android:id="@+id/title"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
    <TextView
        android:id="@+id/subtitle"
        app:layout_constraintTop_toBottomOf="@id/title"
        app:layout_constraintStart_toStartOf="@id/title" />
</androidx.constraintlayout.widget.ConstraintLayout>
// Compose
ConstraintLayout(modifier = Modifier.fillMaxWidth()) {
    val (title, subtitle) = createRefs()
    
    Text(
        text = "Title",
        modifier = Modifier.constrainAs(title) {
            top.linkTo(parent.top)
            start.linkTo(parent.start)
        }
    )
    Text(
        text = "Subtitle", 
        modifier = Modifier.constrainAs(subtitle) {
            top.linkTo(title.bottom)
            start.linkTo(title.start)
        }
    )
}

Include / Merge → Extract Composable

<!-- XML: layout_header.xml -->
<merge>
    <ImageView android:id="@+id/avatar" />
    <TextView android:id="@+id/name" />
</merge>

<!-- Usage -->
<include layout="@layout/layout_header" />
// Compose: Extract as a reusable Composable
@Composable
fun HeaderSection(
    avatarUrl: String,
    name: String,
    modifier: Modifier = Modifier
) {
    Row(modifier = modifier) {
        AsyncImage(model = avatarUrl, contentDescription = null)
        Text(text = name)
    }
}

// Usage
HeaderSection(avatarUrl = user.avatar, name = user.name)

---

Incremental Migration (Interop)

Embedding Compose in XML

<!-- In your XML layout -->
<androidx.compose.ui.platform.ComposeView
    android:id="@+id/compose_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
// In Fragment/Activity
binding.composeView.setContent {
    MaterialTheme {
        MyComposable()
    }
}

Embedding XML Views in Compose

// Use AndroidView for Views that don't have Compose equivalents
@Composable
fun MapViewComposable(modifier: Modifier = Modifier) {
    AndroidView(
        factory = { context ->
            MapView(context).apply {
                // Initialize the view
            }
        },
        update = { mapView ->
            // Update the view when state changes
        },
        modifier = modifier
    )
}

---

State Migration

LiveData to Compose

// Before: Observing in Fragment
viewModel.uiState.observe(viewLifecycleOwner) { state ->
    binding.title.text = state.title
}

// After: Collecting in Compose
@Composable
fun MyScreen(viewModel: MyViewModel = hiltViewModel()) {
    val uiState by viewModel.uiState.collectAsStateWithLifecycle()
    
    Text(text = uiState.title)
}

Click Listeners

// Before: XML + setOnClickListener
binding.submitButton.setOnClickListener {
    viewModel.submit()
}

// After: Lambda in Compose
Button(onClick = { viewModel.submit() }) {
    Text("Submit")
}

---

Checklist

  • [ ] All layouts converted (no include or merge left)
  • [ ] State hoisted properly (no internal mutable state for user input)
  • [ ] Click handlers converted to lambdas
  • [ ] RecyclerView adapters removed (using LazyColumn/LazyRow)
  • [ ] ViewBinding/DataBinding removed
  • [ ] Navigation integrated (NavHost or interop)
  • [ ] Theming applied (MaterialTheme)
  • [ ] Accessibility preserved (content descriptions, touch targets)
  • [ ] Preview annotations added for development
  • [ ] Old XML files deleted

References

Related skills

How it compares

Pick xml-to-compose-migration over generic Compose UI skills when converting specific legacy XML layouts with widget mapping tables and incremental ComposeView interop guidance.

FAQ

How does xml-to-compose-migration handle RecyclerView?

xml-to-compose-migration maps RecyclerView to LazyColumn, LazyRow, or LazyGrid in Jetpack Compose. Items use keyed lazy lists with onClick lambdas, replacing adapter classes and findViewById binding code.

Can xml-to-compose-migration run incrementally?

Yes. xml-to-compose-migration documents ComposeView embedding in existing XML layouts and AndroidView for legacy Views inside Compose, enabling screen-by-screen migration without a full rewrite.

What state migration pattern does the skill recommend?

xml-to-compose-migration recommends replacing LiveData observe blocks with collectAsStateWithLifecycle in Composables, converting click listeners to onClick lambdas, and hoisting TextField state instead of using findViewById.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.