Token导航 LogoToken导航TokenDH.com
研究检索只读github未标认证来源可访问许可证需确认审计通过

xml-to-compose-migrationXML TO compose 迁移

Agent Skill

xml-to-compose-migration 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

5,784

周安装

234

GitHub Stars

772

下载量

1,816
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:xml-to-compose-migration(XML TO compose 迁移)
来源仓库:https://github.com/new-silvermoon/awesome-android-agent-skills
仓库路径:skills/xml-to-compose-migration
安装命令:
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill xml-to-compose-migration
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill xml-to-compose-migration

简介

用于查找、检索和筛选相关信息。

  • 适合根据关键词或任务场景快速定位候选结果。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装使用。
  • 需确认权限范围和维护状态,注意是否触发联网或文件读写操作。
  • xml-to-compose-migration 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

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

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.36%
按下载量换算642

Claude

29.51%
按下载量换算536

Cursor

17.29%
按下载量换算314

Gemini CLI

8.96%
按下载量换算163

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills