@buaa_smat/hometrans 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/README.md +141 -124
  2. package/agents/build-fixer.md +1 -0
  3. package/agents/code-review-fix.md +1 -0
  4. package/agents/code-reviewer.md +1 -0
  5. package/agents/logic-coding.md +1 -0
  6. package/agents/logic-context-builder.md +1 -0
  7. package/agents/review-fixer.md +1 -0
  8. package/agents/self-test-fixer.md +1 -0
  9. package/agents/self-tester.md +260 -233
  10. package/agents/spec-generator.md +1 -0
  11. package/agents/test-tools/autotest/README.md +223 -0
  12. package/agents/test-tools/autotest/config.yaml.example +58 -0
  13. package/agents/test-tools/autotest/pyproject.toml +16 -0
  14. package/agents/test-tools/autotest/report_tool.py +759 -0
  15. package/agents/test-tools/autotest/self_test_runner.py +773 -0
  16. package/agents/test-tools/autotest/testcases_schema.md +143 -0
  17. package/agents/test-tools/autotest/testcases_tool.py +215 -0
  18. package/agents/test-tools/autotest/uv.lock +3156 -0
  19. package/agents/test-tools/harmony_autotest-0.1.0-py3-none-any.whl +0 -0
  20. package/agents/test-tools/hypium-6.1.0.210-py3-none-any.whl +0 -0
  21. package/agents/test-tools/hypium_mcp-0.6.5-py3-none-any.whl +0 -0
  22. package/agents/test-tools/xdevice-6.1.0.210-py3-none-any.whl +0 -0
  23. package/agents/test-tools/xdevice_devicetest-6.1.0.210-py3-none-any.whl +0 -0
  24. package/agents/test-tools/xdevice_ohos-6.1.0.210-py3-none-any.whl +0 -0
  25. package/dist/cli/config-store.js +27 -2
  26. package/dist/cli/config.js +17 -6
  27. package/dist/cli/index.js +3 -2
  28. package/dist/cli/init.js +135 -22
  29. package/dist/cli/mcp.js +2 -2
  30. package/dist/context/index.js +165 -69
  31. package/package.json +59 -60
  32. package/skills/code-dev-review-fix/SKILL.md +279 -0
  33. package/skills/code-dev-review-fix-workspace/evals/evals.json +56 -0
  34. package/skills/code-dev-review-fix-workspace/iteration-1/routing-results.md +23 -0
  35. package/skills/convert_pipeline/SKILL.md +423 -439
  36. package/skills/hmos-resources-convert/SKILL.md +623 -0
  37. package/skills/hmos-resources-convert/evals/evals.json +171 -0
  38. package/skills/hmos-resources-convert/references/conversion-rules.md +663 -0
  39. package/skills/hmos-resources-convert/references/dependency-analysis-rules.md +388 -0
  40. package/skills/hmos-resources-convert/references/resource-mapping-rules.md +457 -0
  41. package/skills/hmos-resources-convert/references/xml-drawable-to-svg-rules.md +513 -0
  42. package/skills/hmos-resources-convert/template/AppScope/app.json5 +10 -0
  43. package/skills/hmos-resources-convert/template/AppScope/resources/base/element/string.json +8 -0
  44. package/skills/hmos-resources-convert/template/AppScope/resources/base/media/background.png +0 -0
  45. package/skills/hmos-resources-convert/template/AppScope/resources/base/media/foreground.png +0 -0
  46. package/skills/hmos-resources-convert/template/AppScope/resources/base/media/layered_image.json +7 -0
  47. package/skills/hmos-resources-convert/template/build-profile.json5 +42 -0
  48. package/skills/hmos-resources-convert/template/code-linter.json5 +32 -0
  49. package/skills/hmos-resources-convert/template/entry/build-profile.json5 +33 -0
  50. package/skills/hmos-resources-convert/template/entry/hvigorfile.ts +6 -0
  51. package/skills/hmos-resources-convert/template/entry/obfuscation-rules.txt +23 -0
  52. package/skills/hmos-resources-convert/template/entry/oh-package.json5 +10 -0
  53. package/skills/hmos-resources-convert/template/entry/src/main/ets/entryability/EntryAbility.ets +48 -0
  54. package/skills/hmos-resources-convert/template/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +16 -0
  55. package/skills/hmos-resources-convert/template/entry/src/main/ets/pages/Index.ets +23 -0
  56. package/skills/hmos-resources-convert/template/entry/src/main/module.json5 +55 -0
  57. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/color.json +8 -0
  58. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/float.json +8 -0
  59. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/element/string.json +16 -0
  60. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/background.png +0 -0
  61. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/foreground.png +0 -0
  62. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/layered_image.json +7 -0
  63. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/media/startIcon.png +0 -0
  64. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/profile/backup_config.json +3 -0
  65. package/skills/hmos-resources-convert/template/entry/src/main/resources/base/profile/main_pages.json +5 -0
  66. package/skills/hmos-resources-convert/template/entry/src/main/resources/dark/element/color.json +8 -0
  67. package/skills/hmos-resources-convert/template/entry/src/mock/mock-config.json5 +2 -0
  68. package/skills/hmos-resources-convert/template/entry/src/ohosTest/ets/test/Ability.test.ets +35 -0
  69. package/skills/hmos-resources-convert/template/entry/src/ohosTest/ets/test/List.test.ets +5 -0
  70. package/skills/hmos-resources-convert/template/entry/src/ohosTest/module.json5 +16 -0
  71. package/skills/hmos-resources-convert/template/entry/src/test/List.test.ets +5 -0
  72. package/skills/hmos-resources-convert/template/entry/src/test/LocalUnit.test.ets +33 -0
  73. package/skills/hmos-resources-convert/template/hvigor/hvigor-config.json5 +23 -0
  74. package/skills/hmos-resources-convert/template/hvigorfile.ts +6 -0
  75. package/skills/hmos-resources-convert/template/oh-package-lock.json5 +28 -0
  76. package/skills/hmos-resources-convert/template/oh-package.json5 +10 -0
  77. package/skills/hmos-resources-convert/tools/apktool.bat +85 -0
  78. package/skills/hmos-resources-convert/tools/apktool_3.0.1.jar +0 -0
  79. package/skills/hmos-ui-align/SKILL.md +182 -0
  80. package/skills/hmos-ui-align/config-example.json +11 -0
  81. package/skills/hmos-ui-align/config.json +11 -0
  82. package/skills/hmos-ui-align/diff_analysis.md +53 -0
  83. package/skills/hmos-ui-align/page_align.md +62 -0
  84. package/skills/hmos-ui-align/readme.md +231 -0
  85. package/skills/hmos-ui-align/references/Comparison_Template.md +2 -0
  86. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -0
  87. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +2089 -0
  88. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -0
  89. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -0
  90. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -0
  91. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -0
  92. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -0
  93. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +903 -0
  94. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -0
  95. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -0
  96. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/MVVM/346/250/241/345/274/217V1.md +911 -0
  97. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/MVVM/346/250/241/345/274/217/357/274/210V1/357/274/211.md +911 -0
  98. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +355 -0
  99. package/skills/hmos-ui-align/references/MVVM/345/274/200/345/217/221/346/226/207/346/241/243//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -0
  100. package/skills/hmos-ui-align/references/UI_Analysis_Template.md +4 -0
  101. package/skills/hmos-ui-align/references/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2535 -0
  102. package/skills/hmos-ui-align/references/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -0
  103. package/skills/hmos-ui-align/references/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -0
  104. package/skills/hmos-ui-align/scripts/app_feature_verify.py +443 -0
  105. package/skills/hmos-ui-align/scripts/navigation-capure.md +37 -0
  106. package/skills/hmos-ui-align/scripts/page_capture.py +592 -0
  107. package/skills/hmos-ui-align-batch/SKILL.md +99 -0
  108. package/skills/hmos-ui-align-batch/references/conversion-procedure.md +180 -0
  109. package/skills/hmos-ui-align-batch/references/mappings/android-to-harmonyOS-ui-atomic-component-mapping-reference.md +2535 -0
  110. package/skills/hmos-ui-align-batch/references/mappings/android-to-harmonyOS-ui-interaction-mapping-reference.md +555 -0
  111. package/skills/hmos-ui-align-batch/references/mappings/android-to-harmonyOS-ui-layout-mapping-reference.md +117 -0
  112. package/skills/hmos-ui-align-batch/references/mvvm/@Link/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/217/214/345/220/221/345/220/214/346/255/245.md +648 -0
  113. package/skills/hmos-ui-align-batch/references/mvvm/@Observed/350/243/205/351/245/260/345/231/250/345/222/214@ObjectLink/350/243/205/351/245/260/345/231/250/357/274/232/345/265/214/345/245/227/347/261/273/345/257/271/350/261/241/345/261/236/346/200/247/345/217/230/345/214/226.md +2089 -0
  114. package/skills/hmos-ui-align-batch/references/mvvm/@Prop/350/243/205/351/245/260/345/231/250/357/274/232/347/210/266/345/255/220/345/215/225/345/220/221/345/220/214/346/255/245.md +1033 -0
  115. package/skills/hmos-ui-align-batch/references/mvvm/@Provide/350/243/205/351/245/260/345/231/250/345/222/214@Consume/350/243/205/351/245/260/345/231/250/357/274/232/344/270/216/345/220/216/344/273/243/347/273/204/344/273/266/345/217/214/345/220/221/345/220/214/346/255/245.md +1183 -0
  116. package/skills/hmos-ui-align-batch/references/mvvm/@State/350/243/205/351/245/260/345/231/250/357/274/232/347/273/204/344/273/266/345/206/205/347/212/266/346/200/201.md +576 -0
  117. package/skills/hmos-ui-align-batch/references/mvvm/@Track/350/243/205/351/245/260/345/231/250/357/274/232class/345/257/271/350/261/241/345/261/236/346/200/247/347/272/247/346/233/264/346/226/260.md +297 -0
  118. package/skills/hmos-ui-align-batch/references/mvvm/@Watch/350/243/205/351/245/260/345/231/250/357/274/232/347/212/266/346/200/201/345/217/230/351/207/217/346/233/264/346/224/271/351/200/232/347/237/245.md +395 -0
  119. package/skills/hmos-ui-align-batch/references/mvvm/AppStorage/357/274/232/345/272/224/347/224/250/345/205/250/345/261/200/347/232/204UI/347/212/266/346/200/201/345/255/230/345/202/250.md +903 -0
  120. package/skills/hmos-ui-align-batch/references/mvvm/Environment/357/274/232/350/256/276/345/244/207/347/216/257/345/242/203/346/237/245/350/257/242.md +106 -0
  121. package/skills/hmos-ui-align-batch/references/mvvm/LocalStorage/357/274/232/351/241/265/351/235/242/347/272/247UI/347/212/266/346/200/201/345/255/230/345/202/250.md +1178 -0
  122. package/skills/hmos-ui-align-batch/references/mvvm/MVVM/346/250/241/345/274/217/357/274/210V1/357/274/211.md +911 -0
  123. package/skills/hmos-ui-align-batch/references/mvvm/PersistentStorage/357/274/232/346/214/201/344/271/205/345/214/226/345/255/230/345/202/250UI/347/212/266/346/200/201.md +355 -0
  124. package/skills/hmos-ui-align-batch/references/mvvm//347/256/241/347/220/206/345/272/224/347/224/250/346/213/245/346/234/211/347/232/204/347/212/266/346/200/201/346/246/202/350/277/260.md +11 -0
  125. package/skills/hmos-ui-align-batch/scripts/android_parse_fast.py +1606 -0
  126. package/skills/self-test/SKILL.md +369 -0
  127. package/skills/self-test/readme.md +309 -0
  128. package/skills/spec-generator-skill/SKILL.md +332 -0
  129. package/skills/spec-generator-skill/references/android-platform-tokens.md +105 -0
  130. package/skills/spec-generator-skill/references/spec-sample-1.md +78 -0
  131. package/skills/spec-generator-skill/references/spec-sample-2.md +58 -0
  132. package/skills/spec-generator-skill/references/spec-sample-3.md +116 -0
  133. package/skills/spec-generator-skill/references/step4-report-template.md +33 -0
  134. package/agents/self-test-setup.md +0 -165
  135. package/dist/context/resources/sdkConfig.json +0 -24
  136. package/src/context/resources/sdkConfig.json +0 -24
@@ -0,0 +1,2535 @@
1
+ # Android-to-HarmonyOS UI Atomic Component Mapping Reference
2
+
3
+ <!-- TODO: Fill in the actual UI atomic component mapping content -->
4
+ <!-- This reference maps Android UI widgets/views to HarmonyOS ArkUI atomic component equivalents -->
5
+ <!-- Covers: TextView→Text, EditText→TextInput, Button→Button, ImageView→Image, CheckBox→Checkbox, Switch→Toggle, ProgressBar→Progress, etc. -->
6
+
7
+
8
+ ## 一、基础视图组件映射
9
+
10
+ ### 1.1 文本类组件
11
+
12
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
13
+ |-------------|------|---------------|---------|------|
14
+ | TextView | `android.widget.TextView` | `Text` | 直接映射 | 文本显示,支持富文本、样式设置 |
15
+ | EditText | `android.widget.EditText` | `TextInput` / `TextArea` | 单行用 TextInput,多行用 TextArea | 文本输入框 |
16
+ | AutoCompleteTextView | `android.widget.AutoCompleteTextView` | `Search` / `Select` | 组合实现 | 自动完成文本输入 |
17
+ | MultiAutoCompleteTextView | `android.widget.MultiAutoCompleteTextView` | 自定义组合 | Select + 标签显示 | 多段自动完成文本输入 |
18
+ | CheckedTextView | `android.widget.CheckedTextView` | `Row` + `Checkbox` + `Text` | 组合实现 | 带选中状态的文本视图 |
19
+ | TextSwitcher | `android.widget.TextSwitcher` | `Swiper` | 配合文本内容 | 文本切换动画容器 |
20
+ | ExtractEditText | `android.widget.ExtractEditText` | `TextArea` | 临时编辑场景 | 输入法提取编辑框 |
21
+ | Chronometer | `android.widget.Chronometer` | `Text` + 定时器 | 自定义实现 | 计时器显示 |
22
+
23
+ ---
24
+
25
+ #### 1.1.1 TextView → Text 属性映射
26
+
27
+ **文本内容属性**
28
+
29
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
30
+ |-------------|---------------|---------|---------|
31
+ | `android:text` | 构造函数参数 | String | Android: `android:text="Hello"`<br/>HarmonyOS: `Text('Hello')` |
32
+ | `android:hint` | `.placeholder()` | String | Android: `android:hint="Enter text"`<br/>HarmonyOS: `Text('').placeholder('Enter text')` |
33
+ | `android:textColor` | `.fontColor()` | Color → ResourceColor | Android: `android:textColor="#FF0000"`<br/>HarmonyOS: `Text('Hello').fontColor('#FF0000')` |
34
+ | `android:textColorHint` | `.placeholderColor()` | Color → ResourceColor | Android: `android:textColorHint="#AAAAAA"`<br/>HarmonyOS: `Text('').placeholderColor('#AAAAAA')` |
35
+ | `android:textColorHighlight` | `.selectionBackgroundColor()` | Color → ResourceColor | Android: `android:textColorHighlight="#FFFF00"`<br/>HarmonyOS: `Text('Hello').selectionBackgroundColor('#FFFF00')` |
36
+ | `android:textColorLink` | 无直接对应 | 需自定义实现 | 使用 SpanString 设置链接颜色 |
37
+
38
+ **文本尺寸属性**
39
+
40
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
41
+ |-------------|---------------|---------|---------|
42
+ | `android:textSize` | `.fontSize()` | sp → fp | Android: `android:textSize="16sp"`<br/>HarmonyOS: `Text('Hello').fontSize(16)` |
43
+ | `android:textScaleX` | `.letterSpacing()` | float (不同行为) | Android: `android:textScaleX="1.2"`<br/>HarmonyOS: `Text('Hello').letterSpacing(0.2)` |
44
+ | `android:lineSpacingExtra` | `.lineHeight()` | dp → vp | Android: `android:lineSpacingExtra="8dp"`<br/>HarmonyOS: `Text('Hello').lineHeight({ extra: 8 })` |
45
+ | `android:lineSpacingMultiplier` | `.lineHeight()` | float (需转换) | Android: `android:lineSpacingMultiplier="1.5"`<br/>HarmonyOS: `Text('Hello').lineHeight({ multiplier: 1.5 })` |
46
+ | `android:letterSpacing` | `.letterSpacing()` | float | Android: `android:letterSpacing="0.1"`<br/>HarmonyOS: `Text('Hello').letterSpacing(0.1)` |
47
+ | `android:ems` | 无直接对应 | 需计算宽度 | 使用 `.width()` 根据字符数计算 |
48
+ | `android:maxEms` | `.constraintSize()` | 需计算宽度 | Android: `android:maxEms="10"`<br/>HarmonyOS: `Text('Hello').constraintSize({ maxWidth: 200 })` |
49
+ | `android:minEms` | `.constraintSize()` | 需计算宽度 | Android: `android:minEms="5"`<br/>HarmonyOS: `Text('Hello').constraintSize({ minWidth: 100 })` |
50
+
51
+ **文本样式属性**
52
+
53
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
54
+ |-------------|---------------|---------|---------|
55
+ | `android:textStyle` | `.fontWeight()` / `.fontStyle()` | enum → enum | Android: `android:textStyle="bold"`<br/>HarmonyOS: `Text('Hello').fontWeight(FontWeight.Bold)` |
56
+ | `android:fontFamily` | `.fontFamily()` | String → String | Android: `android:fontFamily="sans-serif"`<br/>HarmonyOS: `Text('Hello').fontFamily('sans-serif')` |
57
+ | `android:textAllCaps` | `.textCase()` 或手动转换 | boolean → TextCase | Android: `android:textAllCaps="true"`<br/>HarmonyOS: `Text('hello').textCase(TextCase.Upper)` |
58
+ | `android:textLocale` | 无直接对应 | 需设置语言环境 | 使用系统语言环境 |
59
+ | `android:fontFeatureSettings` | 无直接对应 | 需自定义实现 | 使用字体特性 API |
60
+ | `android:fontVariationSettings` | 无直接对应 | 需自定义实现 | 使用字体变体 API |
61
+ | `android:textFontWeight` | `.fontWeight()` | int → FontWeight | Android: `android:textFontWeight="700"`<br/>HarmonyOS: `Text('Hello').fontWeight(FontWeight.Bold)` |
62
+ | `android:lineHeight` | `.lineHeight()` | dp → vp | Android: `android:lineHeight="24dp"`<br/>HarmonyOS: `Text('Hello').lineHeight(24)` |
63
+
64
+ **文本对齐属性**
65
+
66
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
67
+ |-------------|---------------|---------|---------|
68
+ | `android:gravity` | `.textAlign()` | Gravity → TextAlign | Android: `android:gravity="center"`<br/>HarmonyOS: `Text('Hello').textAlign(TextAlign.Center)` |
69
+ | `android:textAlignment` | `.textAlign()` | TextAlignment → TextAlign | Android: `android:textAlignment="center"`<br/>HarmonyOS: `Text('Hello').textAlign(TextAlign.Center)` |
70
+ | `android:textDirection` | 无直接对应 | 需设置布局方向 | 使用 `.direction()` |
71
+ | `android:justificationMode` | 无直接对应 | 需自定义实现 | 使用文本对齐 API |
72
+
73
+ **文本显示与省略属性**
74
+
75
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
76
+ |-------------|---------------|---------|---------|
77
+ | `android:maxLines` | `.maxLines()` | int → int | Android: `android:maxLines="2"`<br/>HarmonyOS: `Text('Hello').maxLines(2)` |
78
+ | `android:minLines` | 无直接对应 | 需自定义实现 | 使用高度约束 |
79
+ | `android:lines` | 无直接对应 | 需自定义实现 | 使用高度约束 |
80
+ | `android:singleLine` | 使用 TextInput | boolean → 组件选择 | Android: `android:singleLine="true"`<br/>HarmonyOS: 使用 TextInput 而非 TextArea |
81
+ | `android:ellipsize` | `.textOverflow()` | TruncateAt → TextOverflow | Android: `android:ellipsize="end"`<br/>HarmonyOS: `Text('Hello').textOverflow({ overflow: TextOverflow.Ellipsis })` |
82
+ | `android:marqueeRepeatLimit` | `.textOverflow()` | int → Marquee | Android: `android:marqueeRepeatLimit="3"`<br/>HarmonyOS: `Text('Hello').textOverflow({ overflow: TextOverflow.Marquee })` |
83
+
84
+ **文本选择属性**
85
+
86
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
87
+ |-------------|---------------|---------|---------|
88
+ | `android:textIsSelectable` | `.copyOption()` | boolean → CopyOptions | Android: `android:textIsSelectable="true"`<br/>HarmonyOS: `Text('Hello').copyOption(CopyOptions.InApp)` |
89
+ | `android:selectable` | `.copyOption()` | boolean → CopyOptions | Android: `android:selectable="true"`<br/>HarmonyOS: `Text('Hello').copyOption(CopyOptions.InApp)` |
90
+ | `android:selectAllOnFocus` | `.selectAll()` | boolean → 方法调用 | Android: `android:selectAllOnFocus="true"`<br/>HarmonyOS: `TextInput().onFocus(() => { textInput.selectAll() })` |
91
+
92
+ **文本外观属性**
93
+
94
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
95
+ |-------------|---------------|---------|---------|
96
+ | `android:textAppearance` | @Styles | @style → @Styles | Android: `android:textAppearance="@style/TextAppearance"`<br/>HarmonyOS: 使用 `@Styles` 装饰器 |
97
+ | `android:shadowColor` | `.shadow()` | Color → shadow | Android: `android:shadowColor="#80000000"`<br/>HarmonyOS: `Text('Hello').shadow({ color: '#80000000', radius: 4 })` |
98
+ | `android:shadowDx` | `.shadow()` | float → shadow.offsetX | Android: `android:shadowDx="2"`<br/>HarmonyOS: `Text('Hello').shadow({ offsetX: 2, offsetY: 2, radius: 4 })` |
99
+ | `android:shadowDy` | `.shadow()` | float → shadow.offsetY | Android: `android:shadowDy="2"`<br/>HarmonyOS: `Text('Hello').shadow({ offsetX: 2, offsetY: 2, radius: 4 })` |
100
+ | `android:shadowRadius` | `.shadow()` | float → shadow.radius | Android: `android:shadowRadius="4"`<br/>HarmonyOS: `Text('Hello').shadow({ radius: 4 })` |
101
+ | `android:elegantTextHeight` | 无直接对应 | 需自定义实现 | 使用字体渲染 API |
102
+ | `android:fallbackLineSpacing` | 无直接对应 | 需自定义实现 | 使用行高设置 |
103
+
104
+ **文本链接属性**
105
+
106
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
107
+ |-------------|---------------|---------|---------|
108
+ | `android:autoLink` | 无直接对应 | 需自定义实现 | 使用 SpanString 或正则表达式 |
109
+ | `android:linksClickable` | 无直接对应 | 需自定义实现 | 使用 SpanString 设置点击事件 |
110
+ | `android:includeFontPadding` | 无直接对应 | 需自定义实现 | 使用行高调整 |
111
+
112
+ ---
113
+
114
+ #### 1.1.2 EditText → TextInput/TextArea 属性映射
115
+
116
+ **输入类型属性**
117
+
118
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
119
+ |-------------|---------------|---------|---------|
120
+ | `android:inputType` | `.type()` | InputType → InputType | Android: `android:inputType="text"`<br/>HarmonyOS: `TextInput().type(InputType.Normal)` |
121
+ | `android:inputType="textPassword"` | `.type()` | password → Password | Android: `android:inputType="textPassword"`<br/>HarmonyOS: `TextInput().type(InputType.Password)` |
122
+ | `android:inputType="number"` | `.type()` | number → Number | Android: `android:inputType="number"`<br/>HarmonyOS: `TextInput().type(InputType.Number)` |
123
+ | `android:inputType="phone"` | `.type()` | phone → PhoneNumber | Android: `android:inputType="phone"`<br/>HarmonyOS: `TextInput().type(InputType.PhoneNumber)` |
124
+ | `android:inputType="email"` | `.type()` | email → Email | Android: `android:inputType="textEmailAddress"`<br/>HarmonyOS: `TextInput().type(InputType.Email)` |
125
+ | `android:inputType="textMultiLine"` | 使用 TextArea | multiLine → TextArea | Android: `android:inputType="textMultiLine"`<br/>HarmonyOS: 使用 TextArea 组件 |
126
+ | `android:maxLength` | `.maxLength()` | int → int | Android: `android:maxLength="100"`<br/>HarmonyOS: `TextInput().maxLength(100)` |
127
+ | `android:password` | `.type()` | boolean → InputType | Android: `android:password="true"`<br/>HarmonyOS: `TextInput().type(InputType.Password)` |
128
+ | `android:phoneNumber` | `.type()` | boolean → InputType | Android: `android:phoneNumber="true"`<br/>HarmonyOS: `TextInput().type(InputType.PhoneNumber)` |
129
+ | `android:numeric` | `.type()` | enum → InputType | Android: `android:numeric="integer"`<br/>HarmonyOS: `TextInput().type(InputType.Number)` |
130
+ | `android:digits` | 无直接对应 | 需自定义实现 | 使用输入过滤器 |
131
+ | `android:capitalize` | 无直接对应 | 需自定义实现 | 使用文本转换 |
132
+ | `android:autoText` | 无直接对应 | 需自定义实现 | 使用输入法设置 |
133
+ | `android:editable` | `.enabled()` | boolean → boolean | Android: `android:editable="false"`<br/>HarmonyOS: `TextInput().enabled(false)` |
134
+ | `android:cursorVisible` | 无直接对应 | 需自定义实现 | 使用光标 API |
135
+
136
+ **IME 选项属性**
137
+
138
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
139
+ |-------------|---------------|---------|---------|
140
+ | `android:imeOptions` | `.enterKeyType()` | ImeOptions → EnterKeyType | Android: `android:imeOptions="actionDone"`<br/>HarmonyOS: `TextInput().enterKeyType(EnterKeyType.Done)` |
141
+ | `android:imeOptions="actionNext"` | `.enterKeyType()` | actionNext → Next | Android: `android:imeOptions="actionNext"`<br/>HarmonyOS: `TextInput().enterKeyType(EnterKeyType.Next)` |
142
+ | `android:imeOptions="actionSearch"` | `.enterKeyType()` | actionSearch → Search | Android: `android:imeOptions="actionSearch"`<br/>HarmonyOS: `TextInput().enterKeyType(EnterKeyType.Search)` |
143
+ | `android:imeOptions="actionSend"` | `.enterKeyType()` | actionSend → Send | Android: `android:imeOptions="actionSend"`<br/>HarmonyOS: `TextInput().enterKeyType(EnterKeyType.Send)` |
144
+ | `android:imeActionLabel` | 无直接对应 | 需自定义实现 | 使用键盘类型设置 |
145
+ | `android:imeActionId` | 无直接对应 | 需自定义实现 | 使用键盘类型设置 |
146
+
147
+ **输入提示属性**
148
+
149
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
150
+ |-------------|---------------|---------|---------|
151
+ | `android:hint` | `.placeholder()` | String → String | Android: `android:hint="Enter name"`<br/>HarmonyOS: `TextInput().placeholder('Enter name')` |
152
+ | `android:textColorHint` | `.placeholderColor()` | Color → ResourceColor | Android: `android:textColorHint="#AAAAAA"`<br/>HarmonyOS: `TextInput().placeholderColor('#AAAAAA')` |
153
+
154
+ ---
155
+
156
+ #### 1.1.3 其他文本组件属性映射
157
+
158
+ **AutoCompleteTextView → Search/Select**
159
+
160
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
161
+ |-------------|---------------|---------|--------|
162
+ | `android:completionThreshold` | Search 组件内置 | int → 自动触发 | Android: `android:completionThreshold="1"`<br/>HarmonyOS: Search 组件自动触发 |
163
+ | `android:dropDownHeight` | 无直接对应 | 需自定义实现 | 使用 Popup 或 Select |
164
+ | `android:dropDownWidth` | 无直接对应 | 需自定义实现 | 使用 Popup 或 Select |
165
+ | `android:dropDownHorizontalOffset` | 无直接对应 | 需自定义实现 | 使用 Popup 或 Select |
166
+ | `android:dropDownVerticalOffset` | 无直接对应 | 需自定义实现 | 使用 Popup 或 Select |
167
+
168
+ **Chronometer → Text + 定时器**
169
+
170
+ | Android XML | HarmonyOS 实现 | 类型转换 | 代码示例 |
171
+ |-------------|---------------|---------|---------|
172
+ | `android:format` | 使用 setInterval | String → 格式化 | Android: `android:format="%s"`<br/>HarmonyOS: 使用 `setInterval` 更新 Text |
173
+ | `android:countDown` | 自定义逻辑 | boolean → 计数方向 | Android: `android:countDown="true"`<br/>HarmonyOS: 自定义计数逻辑 |
174
+ | `android:base` | 使用 Date | long → Date | Android: `android:base="1000"`<br/>HarmonyOS: 使用 Date 对象 |
175
+
176
+ ---
177
+
178
+ #### 1.1.4 文本组件通用布局属性映射
179
+
180
+ **尺寸属性**
181
+
182
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
183
+ |-------------|---------------|---------|---------|
184
+ | `android:layout_width` | `.width()` | dp → vp / match_parent → '100%' | Android: `android:layout_width="100dp"`<br/>HarmonyOS: `Text('Hello').width(100)` |
185
+ | `android:layout_width="match_parent"` | `.width()` | match_parent → '100%' | Android: `android:layout_width="match_parent"`<br/>HarmonyOS: `Text('Hello').width('100%')` |
186
+ | `android:layout_width="wrap_content"` | 无需设置 | wrap_content → 自适应 | Android: `android:layout_width="wrap_content"`<br/>HarmonyOS: 无需设置,自动适应 |
187
+ | `android:layout_height` | `.height()` | dp → vp / match_parent → '100%' | Android: `android:layout_height="50dp"`<br/>HarmonyOS: `Text('Hello').height(50)` |
188
+ | `android:minWidth` | `.constraintSize()` | dp → vp | Android: `android:minWidth="100dp"`<br/>HarmonyOS: `Text('Hello').constraintSize({ minWidth: 100 })` |
189
+ | `android:maxWidth` | `.constraintSize()` | dp → vp | Android: `android:maxWidth="200dp"`<br/>HarmonyOS: `Text('Hello').constraintSize({ maxWidth: 200 })` |
190
+ | `android:minHeight` | `.constraintSize()` | dp → vp | Android: `android:minHeight="30dp"`<br/>HarmonyOS: `Text('Hello').constraintSize({ minHeight: 30 })` |
191
+ | `android:maxHeight` | `.constraintSize()` | dp → vp | Android: `android:maxHeight="100dp"`<br/>HarmonyOS: `Text('Hello').constraintSize({ maxHeight: 100 })` |
192
+
193
+ **边距与内边距属性**
194
+
195
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
196
+ |-------------|---------------|---------|---------|
197
+ | `android:layout_margin` | `.margin()` | dp → vp | Android: `android:layout_margin="10dp"`<br/>HarmonyOS: `Text('Hello').margin(10)` |
198
+ | `android:layout_marginTop` | `.margin({ top })` | dp → vp | Android: `android:layout_marginTop="10dp"`<br/>HarmonyOS: `Text('Hello').margin({ top: 10 })` |
199
+ | `android:layout_marginBottom` | `.margin({ bottom })` | dp → vp | Android: `android:layout_marginBottom="10dp"`<br/>HarmonyOS: `Text('Hello').margin({ bottom: 10 })` |
200
+ | `android:layout_marginLeft` | `.margin({ left })` | dp → vp | Android: `android:layout_marginLeft="10dp"`<br/>HarmonyOS: `Text('Hello').margin({ left: 10 })` |
201
+ | `android:layout_marginRight` | `.margin({ right })` | dp → vp | Android: `android:layout_marginRight="10dp"`<br/>HarmonyOS: `Text('Hello').margin({ right: 10 })` |
202
+ | `android:layout_marginStart` | `.margin({ start })` | dp → vp | Android: `android:layout_marginStart="10dp"`<br/>HarmonyOS: `Text('Hello').margin({ start: 10 })` |
203
+ | `android:layout_marginEnd` | `.margin({ end })` | dp → vp | Android: `android:layout_marginEnd="10dp"`<br/>HarmonyOS: `Text('Hello').margin({ end: 10 })` |
204
+ | `android:padding` | `.padding()` | dp → vp | Android: `android:padding="10dp"`<br/>HarmonyOS: `Text('Hello').padding(10)` |
205
+ | `android:paddingTop` | `.padding({ top })` | dp → vp | Android: `android:paddingTop="10dp"`<br/>HarmonyOS: `Text('Hello').padding({ top: 10 })` |
206
+ | `android:paddingBottom` | `.padding({ bottom })` | dp → vp | Android: `android:paddingBottom="10dp"`<br/>HarmonyOS: `Text('Hello').padding({ bottom: 10 })` |
207
+ | `android:paddingLeft` | `.padding({ left })` | dp → vp | Android: `android:paddingLeft="10dp"`<br/>HarmonyOS: `Text('Hello').padding({ left: 10 })` |
208
+ | `android:paddingRight` | `.padding({ right })` | dp → vp | Android: `android:paddingRight="10dp"`<br/>HarmonyOS: `Text('Hello').padding({ right: 10 })` |
209
+ | `android:paddingStart` | `.padding({ start })` | dp → vp | Android: `android:paddingStart="10dp"`<br/>HarmonyOS: `Text('Hello').padding({ start: 10 })` |
210
+ | `android:paddingEnd` | `.padding({ end })` | dp → vp | Android: `android:paddingEnd="10dp"`<br/>HarmonyOS: `Text('Hello').padding({ end: 10 })` |
211
+
212
+ **对齐与权重属性**
213
+
214
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
215
+ |-------------|---------------|---------|---------|
216
+ | `android:layout_gravity` | `.align()` / `.alignSelf()` | Gravity → Alignment | Android: `android:layout_gravity="center"`<br/>HarmonyOS: `Text('Hello').align(Alignment.Center)` |
217
+ | `android:layout_weight` | `.layoutWeight()` | float → number | Android: `android:layout_weight="1"`<br/>HarmonyOS: `Text('Hello').layoutWeight(1)` |
218
+
219
+ **显示属性**
220
+
221
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
222
+ |-------------|---------------|---------|---------|
223
+ | `android:visibility` | `.visibility()` | enum → Visibility | Android: `android:visibility="gone"`<br/>HarmonyOS: `Text('Hello').visibility(Visibility.None)` |
224
+ | `android:visibility="invisible"` | `.visibility()` | invisible → Hidden | Android: `android:visibility="invisible"`<br/>HarmonyOS: `Text('Hello').visibility(Visibility.Hidden)` |
225
+ | `android:visibility="visible"` | `.visibility()` | visible → Visible | Android: `android:visibility="visible"`<br/>HarmonyOS: `Text('Hello').visibility(Visibility.Visible)` |
226
+ | `android:alpha` | `.opacity()` | float (0-1) → number (0-1) | Android: `android:alpha="0.5"`<br/>HarmonyOS: `Text('Hello').opacity(0.5)` |
227
+ | `android:background` | `.backgroundColor()` | Color → ResourceColor | Android: `android:background="#FF0000"`<br/>HarmonyOS: `Text('Hello').backgroundColor('#FF0000')` |
228
+ | `android:background` | `.backgroundImage()` | Drawable → Resource | Android: `android:background="@drawable/bg"`<br/>HarmonyOS: `Text('Hello').backgroundImage($r('app.media.bg'))` |
229
+
230
+ **交互属性**
231
+
232
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
233
+ |-------------|---------------|---------|---------|
234
+ | `android:enabled` | `.enabled()` | boolean → boolean | Android: `android:enabled="false"`<br/>HarmonyOS: `Text('Hello').enabled(false)` |
235
+ | `android:clickable` | `.onClick()` | boolean → 事件回调 | Android: `android:clickable="true"`<br/>HarmonyOS: `Text('Hello').onClick(() => { ... })` |
236
+ | `android:focusable` | `.focusable()` | boolean → boolean | Android: `android:focusable="true"`<br/>HarmonyOS: `Text('Hello').focusable(true)` |
237
+ | `android:focusableInTouchMode` | 无直接对应 | 需自定义实现 | 使用焦点 API |
238
+
239
+ **变换属性**
240
+
241
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
242
+ |-------------|---------------|---------|---------|
243
+ | `android:rotation` | `.rotate()` | float → { angle: number } | Android: `android:rotation="90"`<br/>HarmonyOS: `Text('Hello').rotate({ angle: 90 })` |
244
+ | `android:scaleX` | `.scale()` | float → { x: number } | Android: `android:scaleX="1.5"`<br/>HarmonyOS: `Text('Hello').scale({ x: 1.5 })` |
245
+ | `android:scaleY` | `.scale()` | float → { y: number } | Android: `android:scaleY="1.5"`<br/>HarmonyOS: `Text('Hello').scale({ y: 1.5 })` |
246
+ | `android:translationX` | `.translate()` | float → { x: number } | Android: `android:translationX="100"`<br/>HarmonyOS: `Text('Hello').translate({ x: 100 })` |
247
+ | `android:translationY` | `.translate()` | float → { y: number } | Android: `android:translationY="100"`<br/>HarmonyOS: `Text('Hello').translate({ y: 100 })` |
248
+ | `android:translationZ` | 无直接对应 | 需自定义实现 | 使用层级和阴影 |
249
+ | `android:pivotX` | 无直接对应 | 需自定义实现 | 使用变换中心 API |
250
+ | `android:pivotY` | 无直接对应 | 需自定义实现 | 使用变换中心 API |
251
+
252
+ **阴影与效果属性**
253
+
254
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
255
+ |-------------|---------------|---------|---------|
256
+ | `android:elevation` | `.shadow()` | dp → shadow | Android: `android:elevation="8dp"`<br/>HarmonyOS: `Text('Hello').shadow({ radius: 8, color: '#30000000', offsetY: 4 })` |
257
+ | `android:outlineProvider` | 无直接对应 | 需自定义实现 | 使用裁剪 API |
258
+ | `android:clipToOutline` | `.clip()` | boolean → boolean | Android: `android:clipToOutline="true"`<br/>HarmonyOS: `Text('Hello').clip(true)` |
259
+
260
+ **无障碍属性**
261
+
262
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
263
+ |-------------|---------------|---------|---------|
264
+ | `android:contentDescription` | `.accessibilityText()` | String → String | Android: `android:contentDescription="Button label"`<br/>HarmonyOS: `Text('Hello').accessibilityText('Button label')` |
265
+ | `android:labelFor` | 无直接对应 | 需自定义实现 | 使用无障碍组 |
266
+ | `android:importantForAccessibility` | `.accessibilityLevel()` | enum → AccessibilityLevel | Android: `android:importantForAccessibility="yes"`<br/>HarmonyOS: `Text('Hello').accessibilityLevel('auto')` |
267
+
268
+ ---
269
+
270
+ #### 1.1.5 单位换算说明
271
+
272
+ | Android 单位 | HarmonyOS 单位 | 换算关系 | 说明 |
273
+ |-------------|---------------|---------|------|
274
+ | `dp` (Density-independent Pixels) | `vp` (Virtual Pixels) | 1dp ≈ 1vp | 密度无关像素,用于布局尺寸 |
275
+ | `sp` (Scale-independent Pixels) | `fp` (Font Pixels) | 1sp ≈ 1fp | 字体像素,用于文本大小,会随系统字体缩放 |
276
+ | `px` (Pixels) | `px` (Pixels) | 1px = 1px | 物理像素,不推荐使用 |
277
+ | `dip` | `vp` | 1dip ≈ 1vp | dp 的别名 |
278
+ | `in` (Inches) | 需转换 | 1in ≈ 160vp | 英寸,1英寸 = 160dp |
279
+ | `mm` (Millimeters) | 需转换 | 1mm ≈ 6.33vp | 毫米,1毫米 = 6.33dp |
280
+ | `pt` (Points) | 需转换 | 1pt ≈ 2.12vp | 点,1点 = 2.12dp |
281
+
282
+ ---
283
+
284
+ #### 1.1.6 文本组件属性映射统计
285
+
286
+ | 映射类型 | 数量 | 占比 |
287
+ |---------|------|------|
288
+ | 直接映射 | 45 | ~50% |
289
+ | 需类型转换 | 30 | ~33% |
290
+ | 需组合实现 | 10 | ~11% |
291
+ | 无直接对应 | 5 | ~6% |
292
+ | **总计** | **90** | **100%** |
293
+
294
+ **映射复杂度说明:**
295
+ - **直接映射**:属性名称和功能基本一致,仅需简单语法调整
296
+ - **需类型转换**:需要将 Android 的数据类型转换为 HarmonyOS 对应类型(如 sp→fp, dp→vp)
297
+ - **需组合实现**:需要多个 HarmonyOS 属性或组件组合才能实现 Android 单个属性的功能
298
+ - **无直接对应**:HarmonyOS 暂无对应功能,需要自定义实现或使用替代方案
299
+
300
+ ### 1.2 按钮类组件
301
+
302
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
303
+ |-------------|------|---------------|---------|------|
304
+ | Button | `android.widget.Button` | `Button` | 直接映射 | 普通按钮 |
305
+ | ImageButton | `android.widget.ImageButton` | `Button` + `Image` | 组合实现 | 图片按钮 |
306
+ | CompoundButton | `android.widget.CompoundButton` | `Checkbox` / `Radio` / `Toggle` | 根据类型选择 | 复合按钮基类 |
307
+ | CheckBox | `android.widget.CheckBox` | `Checkbox` | 直接映射 | 复选框 |
308
+ | RadioButton | `android.widget.RadioButton` | `Radio` + `RadioContainer` | 需容器 | 单选按钮 |
309
+ | RadioGroup | `android.widget.RadioGroup` | `RadioContainer` | 直接映射 | 单选按钮组 |
310
+ | ToggleButton | `android.widget.ToggleButton` | `Toggle` (ButtonType: Button) | 直接映射 | 开关按钮(文字切换) |
311
+ | Switch | `android.widget.Switch` | `Toggle` (ButtonType: Switch) | 直接映射 | 开关控件(滑动式) |
312
+
313
+ ---
314
+
315
+ #### 1.2.1 Button → Button 属性映射
316
+
317
+ **按钮内容属性**
318
+
319
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
320
+ |-------------|---------------|---------|---------|
321
+ | `android:text` | 构造函数参数 | String | Android: `android:text="Click Me"`<br/>HarmonyOS: `Button('Click Me')` |
322
+ | `android:textColor` | `.fontColor()` | Color → ResourceColor | Android: `android:textColor="#FFFFFF"`<br/>HarmonyOS: `Button('Click').fontColor('#FFFFFF')` |
323
+ | `android:textSize` | `.fontSize()` | sp → fp | Android: `android:textSize="16sp"`<br/>HarmonyOS: `Button('Click').fontSize(16)` |
324
+ | `android:textStyle` | `.fontWeight()` | enum → FontWeight | Android: `android:textStyle="bold"`<br/>HarmonyOS: `Button('Click').fontWeight(FontWeight.Bold)` |
325
+
326
+ **按钮类型属性**
327
+
328
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
329
+ |-------------|---------------|---------|---------|
330
+ | `android:background` | `.type()` + `.backgroundColor()` | Drawable → ButtonType | Android: `android:background="@drawable/bg"`<br/>HarmonyOS: `Button('Click').type(ButtonType.Normal)` |
331
+ | `android:stateListAnimator` | 无直接对应 | 需自定义实现 | 使用动画 API |
332
+ | `android:elevation` | `.shadow()` | dp → shadow | Android: `android:elevation="4dp"`<br/>HarmonyOS: `Button('Click').shadow({ radius: 4 })` |
333
+
334
+ **Material Button 特有属性**
335
+
336
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
337
+ |-------------|---------------|---------|---------|
338
+ | `app:cornerRadius` | 无直接对应 | 需自定义实现 | 使用 `.borderRadius()` |
339
+ | `app:icon` | 无直接对应 | 需组合实现 | 使用 `Button` + `Image` 组合 |
340
+ | `app:iconTint` | 无直接对应 | 需组合实现 | 使用 `Image` 的 `.renderMode()` |
341
+ | `app:iconGravity` | 无直接对应 | 需组合实现 | 使用 `Row` 布局调整 |
342
+ | `app:iconPadding` | 无直接对应 | 需组合实现 | 使用 `.padding()` |
343
+ | `app:iconSize` | 无直接对应 | 需组合实现 | 使用 `Image` 的 `.width()` `.height()` |
344
+ | `app:strokeColor` | `.border()` | Color → borderColor | Android: `app:strokeColor="#FF0000"`<br/>HarmonyOS: `Button('Click').border({ color: '#FF0000' })` |
345
+ | `app:strokeWidth` | `.border()` | dp → borderWidth | Android: `app:strokeWidth="2dp"`<br/>HarmonyOS: `Button('Click').border({ width: 2 })` |
346
+ | `app:rippleColor` | 无直接对应 | 需自定义实现 | 使用状态样式 |
347
+
348
+ **按钮状态属性**
349
+
350
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
351
+ |-------------|---------------|---------|---------|
352
+ | `android:enabled` | `.enabled()` | boolean → boolean | Android: `android:enabled="false"`<br/>HarmonyOS: `Button('Click').enabled(false)` |
353
+ | `android:clickable` | `.onClick()` | boolean → 事件回调 | Android: `android:clickable="true"`<br/>HarmonyOS: `Button('Click').onClick(() => { ... })` |
354
+ | `android:focusable` | `.focusable()` | boolean → boolean | Android: `android:focusable="true"`<br/>HarmonyOS: `Button('Click').focusable(true)` |
355
+ | `android:selected` | 无直接对应 | 需状态管理 | 使用 `@State` 变量 |
356
+ | `android:pressed` | 无直接对应 | 需状态管理 | 使用 `.stateEffect()` |
357
+
358
+ **按钮交互属性**
359
+
360
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
361
+ |-------------|---------------|---------|---------|
362
+ | `android:onClick` | `.onClick()` | 方法引用 → 回调函数 | Android: `android:onClick="onClick"`<br/>HarmonyOS: `Button('Click').onClick(() => { ... })` |
363
+ | `android:longClickable` | `.onLongPress()` | boolean → 回调函数 | Android: `android:longClickable="true"`<br/>HarmonyOS: `Button('Click').onLongPress(() => { ... })` |
364
+
365
+ ---
366
+
367
+ #### 1.2.2 ImageButton → Button + Image 组合实现
368
+
369
+ **ImageButton 属性映射**
370
+
371
+ | Android XML | HarmonyOS 实现 | 类型转换 | 代码示例 |
372
+ |-------------|---------------|---------|---------|
373
+ | `android:src` | `Image` 组件 | Drawable → Resource | Android: `android:src="@drawable/icon"`<br/>HarmonyOS: `Button() { Image($r('app.media.icon')) }` |
374
+ | `android:scaleType` | `Image.objectFit()` | ScaleType → ImageFit | Android: `android:scaleType="centerCrop"`<br/>HarmonyOS: `Image($r('app.media.icon')).objectFit(ImageFit.Cover)` |
375
+ | `android:adjustViewBounds` | 无直接对应 | 需自定义实现 | 使用尺寸约束 |
376
+ | `android:tint` | `Image.renderMode()` | Color → RenderMode | Android: `android:tint="#FF0000"`<br/>HarmonyOS: `Image($r('app.media.icon')).renderMode(ImageRenderMode.Template)` |
377
+ | `android:tintMode` | 无直接对应 | 需自定义实现 | 使用渲染模式 |
378
+
379
+ **组合示例:**
380
+ ```typescript
381
+ // Android
382
+ <ImageButton
383
+ android:layout_width="48dp"
384
+ android:layout_height="48dp"
385
+ android:src="@drawable/ic_back"
386
+ android:background="?attr/selectableItemBackgroundBorderless"
387
+ android:contentDescription="Back" />
388
+
389
+ // HarmonyOS
390
+ Button() {
391
+ Image($r('app.media.ic_back'))
392
+ .width(24)
393
+ .height(24)
394
+ .objectFit(ImageFit.Contain)
395
+ }
396
+ .width(48)
397
+ .height(48)
398
+ .type(ButtonType.Normal)
399
+ .backgroundColor(Color.Transparent)
400
+ .onClick(() => {
401
+ // Handle click
402
+ })
403
+ ```
404
+
405
+ ---
406
+
407
+ #### 1.2.3 CheckBox → Checkbox 属性映射
408
+
409
+ **CheckBox 属性映射**
410
+
411
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
412
+ |-------------|---------------|---------|---------|
413
+ | `android:checked` | `.select()` | boolean → boolean | Android: `android:checked="true"`<br/>HarmonyOS: `Checkbox().select(true)` |
414
+ | `android:button` | 无直接对应 | 需自定义实现 | 使用自定义样式 |
415
+ | `android:buttonTint` | 无直接对应 | 需自定义实现 | 使用状态样式 |
416
+ | `android:buttonTintMode` | 无直接对应 | 需自定义实现 | 使用状态样式 |
417
+
418
+ **CheckBox 事件映射**
419
+
420
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
421
+ |-------------|---------------|---------|---------|
422
+ | `android:OnCheckedChangeListener` | `.onChange()` | 监听器 → 回调函数 | Android: `setOnCheckedChangeListener(...)`<br/>HarmonyOS: `Checkbox().onChange((isSelected: boolean) => { ... })` |
423
+
424
+ ---
425
+
426
+ #### 1.2.4 RadioButton + RadioGroup → Radio + RadioContainer 属性映射
427
+
428
+ **RadioButton 属性映射**
429
+
430
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
431
+ |-------------|---------------|---------|---------|
432
+ | `android:checked` | 无直接对应 | 由 RadioContainer 管理 | 使用 RadioContainer 的默认值 |
433
+ | `android:button` | 无直接对应 | 需自定义实现 | 使用自定义样式 |
434
+ | `android:buttonTint` | 无直接对应 | 需自定义实现 | 使用状态样式 |
435
+
436
+ **RadioGroup 属性映射**
437
+
438
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
439
+ |-------------|---------------|---------|---------|
440
+ | `android:orientation` | 无直接对应 | 需布局选择 | 垂直用 Column,水平用 Row |
441
+ | `android:checkedButton` | 无直接对应 | 需状态管理 | 使用 `@State` 变量管理选中项 |
442
+
443
+ **组合示例:**
444
+ ```typescript
445
+ // Android
446
+ <RadioGroup
447
+ android:layout_width="match_parent"
448
+ android:layout_height="wrap_content"
449
+ android:orientation="vertical">
450
+ <RadioButton
451
+ android:id="@+id/radio1"
452
+ android:layout_width="wrap_content"
453
+ android:layout_height="wrap_content"
454
+ android:text="Option 1" />
455
+ <RadioButton
456
+ android:id="@+id/radio2"
457
+ android:layout_width="wrap_content"
458
+ android:layout_height="wrap_content"
459
+ android:text="Option 2" />
460
+ </RadioGroup>
461
+
462
+ // HarmonyOS
463
+ @State selectedIndex: number = 0
464
+
465
+ RadioContainer({ group: 'radioGroup' }) {
466
+ Radio({ value: '0', group: 'radioGroup' })
467
+ .onChange((isSelected: boolean) => {
468
+ if (isSelected) {
469
+ this.selectedIndex = 0;
470
+ }
471
+ })
472
+ Radio({ value: '1', group: 'radioGroup' })
473
+ .onChange((isSelected: boolean) => {
474
+ if (isSelected) {
475
+ this.selectedIndex = 1;
476
+ }
477
+ })
478
+ }
479
+ ```
480
+
481
+ ---
482
+
483
+ #### 1.2.5 Switch/ToggleButton → Toggle 属性映射
484
+
485
+ **Toggle 属性映射**
486
+
487
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
488
+ |-------------|---------------|---------|---------|
489
+ | `android:checked` | `.select()` | boolean → boolean | Android: `android:checked="true"`<br/>HarmonyOS: `Toggle().select(true)` |
490
+ | `android:textOn` | 无直接对应 | 需组合实现 | 使用 `Toggle` + `Text` 组合 |
491
+ | `android:textOff` | 无直接对应 | 需组合实现 | 使用 `Toggle` + `Text` 组合 |
492
+ | `android:thumb` | 无直接对应 | 需自定义实现 | 使用自定义样式 |
493
+ | `android:thumbTint` | 无直接对应 | 需自定义实现 | 使用状态样式 |
494
+ | `android:track` | 无直接对应 | 需自定义实现 | 使用自定义样式 |
495
+ | `android:trackTint` | 无直接对应 | 需自定义实现 | 使用状态样式 |
496
+ | `android:showText` | 无直接对应 | 需组合实现 | 使用 `Toggle` + `Text` 组合 |
497
+ | `android:splitTrack` | 无直接对应 | 需自定义实现 | 使用自定义样式 |
498
+
499
+ **Toggle 类型选择**
500
+
501
+ | Android 组件 | HarmonyOS 类型 | 代码示例 |
502
+ |-------------|---------------|---------|
503
+ | `Switch` | `ToggleType.Switch` | `Toggle({ type: ToggleType.Switch })` |
504
+ | `ToggleButton` | `ToggleType.Button` | `Toggle({ type: ToggleType.Button })` |
505
+
506
+ **Toggle 事件映射**
507
+
508
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
509
+ |-------------|---------------|---------|---------|
510
+ | `android:OnCheckedChangeListener` | `.onChange()` | 监听器 → 回调函数 | Android: `setOnCheckedChangeListener(...)`<br/>HarmonyOS: `Toggle().onChange((isOn: boolean) => { ... })` |
511
+
512
+ ---
513
+
514
+ #### 1.2.6 按钮组件通用布局属性映射
515
+
516
+ 按钮组件继承所有通用布局属性,参考 1.1.4 文本组件通用布局属性映射。
517
+
518
+ **额外按钮特定属性**
519
+
520
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
521
+ |-------------|---------------|---------|---------|
522
+ | `android:minWidth` | `.constraintSize()` | dp → vp | Android: `android:minWidth="88dp"`<br/>HarmonyOS: `Button('Click').constraintSize({ minWidth: 88 })` |
523
+ | `android:minHeight` | `.constraintSize()` | dp → vp | Android: `android:minHeight="48dp"`<br/>HarmonyOS: `Button('Click').constraintSize({ minHeight: 48 })` |
524
+ | `android:paddingStart` | `.padding({ start })` | dp → vp | Android: `android:paddingStart="16dp"`<br/>HarmonyOS: `Button('Click').padding({ start: 16 })` |
525
+ | `android:paddingEnd` | `.padding({ end })` | dp → vp | Android: `android:paddingEnd="16dp"`<br/>HarmonyOS: `Button('Click').padding({ end: 16 })` |
526
+
527
+ ---
528
+
529
+ #### 1.2.7 按钮组件属性映射统计
530
+
531
+ | 映射类型 | 数量 | 占比 |
532
+ |---------|------|------|
533
+ | 直接映射 | 20 | ~45% |
534
+ | 需类型转换 | 10 | ~23% |
535
+ | 需组合实现 | 10 | ~23% |
536
+ | 无直接对应 | 4 | ~9% |
537
+ | **总计** | **44** | **100%** |
538
+
539
+ ---
540
+
541
+ ### 1.3 图片类组件
542
+
543
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
544
+ |-------------|------|---------------|---------|------|
545
+ | ImageView | `android.widget.ImageView` | `Image` | 直接映射 | 图片显示组件 |
546
+ | QuickContactBadge | `android.widget.QuickContactBadge` | `Badge` + `Image` | 组合实现 | 快捷联系人徽章 |
547
+
548
+ ---
549
+
550
+ #### 1.3.1 ImageView → Image 属性映射
551
+
552
+ **图片源属性**
553
+
554
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
555
+ |-------------|---------------|---------|---------|
556
+ | `android:src` | 构造函数参数 | Drawable → Resource | Android: `android:src="@drawable/image"`<br/>HarmonyOS: `Image($r('app.media.image'))` |
557
+ | `android:srcCompat` | 构造函数参数 | Drawable → Resource | Android: `android:srcCompat="@drawable/image"`<br/>HarmonyOS: `Image($r('app.media.image'))` |
558
+
559
+ **图片缩放类型属性**
560
+
561
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
562
+ |-------------|---------------|---------|---------|
563
+ | `android:scaleType` | `.objectFit()` | ScaleType → ImageFit | Android: `android:scaleType="centerCrop"`<br/>HarmonyOS: `Image($r('app.media.image')).objectFit(ImageFit.Cover)` |
564
+ | `android:scaleType="center"` | `.objectFit()` | center → ImageFit.None | Android: `android:scaleType="center"`<br/>HarmonyOS: `Image($r('app.media.image')).objectFit(ImageFit.None)` |
565
+ | `android:scaleType="centerCrop"` | `.objectFit()` | centerCrop → ImageFit.Cover | Android: `android:scaleType="centerCrop"`<br/>HarmonyOS: `Image($r('app.media.image')).objectFit(ImageFit.Cover)` |
566
+ | `android:scaleType="centerInside"` | `.objectFit()` | centerInside → ImageFit.Contain | Android: `android:scaleType="centerInside"`<br/>HarmonyOS: `Image($r('app.media.image')).objectFit(ImageFit.Contain)` |
567
+ | `android:scaleType="fitCenter"` | `.objectFit()` | fitCenter → ImageFit.Contain | Android: `android:scaleType="fitCenter"`<br/>HarmonyOS: `Image($r('app.media.image')).objectFit(ImageFit.Contain)` |
568
+ | `android:scaleType="fitXY"` | `.objectFit()` | fitXY → ImageFit.Fill | Android: `android:scaleType="fitXY"`<br/>HarmonyOS: `Image($r('app.media.image')).objectFit(ImageFit.Fill)` |
569
+ | `android:scaleType="fitStart"` | `.objectFit()` | fitStart → ImageFit.Contain | Android: `android:scaleType="fitStart"`<br/>HarmonyOS: `Image($r('app.media.image')).objectFit(ImageFit.Contain)` |
570
+ | `android:scaleType="fitEnd"` | `.objectFit()` | fitEnd → ImageFit.Contain | Android: `android:scaleType="fitEnd"`<br/>HarmonyOS: `Image($r('app.media.image')).objectFit(ImageFit.Contain)` |
571
+
572
+ **图片调整属性**
573
+
574
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
575
+ |-------------|---------------|---------|---------|
576
+ | `android:adjustViewBounds` | 无直接对应 | 需自定义实现 | 使用尺寸约束 |
577
+ | `android:maxWidth` | `.constraintSize()` | dp → vp | Android: `android:maxWidth="200dp"`<br/>HarmonyOS: `Image($r('app.media.image')).constraintSize({ maxWidth: 200 })` |
578
+ | `android:maxHeight` | `.constraintSize()` | dp → vp | Android: `android:maxHeight="200dp"`<br/>HarmonyOS: `Image($r('app.media.image')).constraintSize({ maxHeight: 200 })` |
579
+
580
+ **图片着色属性**
581
+
582
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
583
+ |-------------|---------------|---------|---------|
584
+ | `android:tint` | `.renderMode()` + `.colorFilter()` | Color → RenderMode | Android: `android:tint="#FF0000"`<br/>HarmonyOS: `Image($r('app.media.image')).renderMode(ImageRenderMode.Template)` |
585
+ | `android:tintMode` | 无直接对应 | 需自定义实现 | 使用渲染模式 |
586
+ | `android:colorFilter` | 无直接对应 | 需自定义实现 | 使用颜色滤镜 API |
587
+
588
+ **图片内容描述属性**
589
+
590
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
591
+ |-------------|---------------|---------|---------|
592
+ | `android:contentDescription` | `.alt()` | String → String | Android: `android:contentDescription="Image description"`<br/>HarmonyOS: `Image($r('app.media.image')).alt('Image description')` |
593
+
594
+ **图片裁剪属性**
595
+
596
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
597
+ |-------------|---------------|---------|---------|
598
+ | `android:cropToPadding` | 无直接对应 | 需自定义实现 | 使用裁剪 API |
599
+ | `android:baseline` | 无直接对应 | 需自定义实现 | 使用基线对齐 API |
600
+
601
+ **图片布局方向属性**
602
+
603
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
604
+ |-------------|---------------|---------|---------|
605
+ | `android:layoutDirection` | 无直接对应 | 需自定义实现 | 使用布局方向 API |
606
+
607
+ ---
608
+
609
+ #### 1.3.2 Image 组件加载属性
610
+
611
+ **加载状态属性**
612
+
613
+ | Android 方法 | HarmonyOS 属性 | 类型转换 | 代码示例 |
614
+ |-------------|---------------|---------|---------|
615
+ | `setImageResource()` | 构造函数参数 | int → Resource | Android: `imageView.setImageResource(R.drawable.image)`<br/>HarmonyOS: `Image($r('app.media.image'))` |
616
+ | `setImageURI()` | 构造函数参数 | String → String | Android: `imageView.setImageURI("https://example.com/image.jpg")`<br/>HarmonyOS: `Image('https://example.com/image.jpg')` |
617
+ | `setImageBitmap()` | 无直接对应 | 需自定义实现 | 使用 PixelMap |
618
+ | `setImageDrawable()` | 无直接对应 | 需自定义实现 | 使用 Drawable |
619
+
620
+ **加载事件属性**
621
+
622
+ | Android 监听器 | HarmonyOS 属性 | 类型转换 | 代码示例 |
623
+ |-------------|---------------|---------|---------|
624
+ | `OnLoadCompleteListener` | `.onComplete()` | 监听器 → 回调函数 | Android: `setOnLoadCompleteListener(...)`<br/>HarmonyOS: `Image($r('app.media.image')).onComplete(() => { ... })` |
625
+ | `OnLoadFailedListener` | `.onError()` | 监听器 → 回调函数 | Android: `setOnLoadFailedListener(...)`<br/>HarmonyOS: `Image($r('app.media.image')).onError(() => { ... })` |
626
+ | `OnProgressListener` | 无直接对应 | 需自定义实现 | 使用加载进度 API |
627
+
628
+ ---
629
+
630
+ **ImageFit 枚举值映射**
631
+
632
+ | Android ScaleType | HarmonyOS ImageFit | 说明 |
633
+ |-----------------|-------------------|------|
634
+ | `center` | `ImageFit.None` | 不缩放,居中显示 |
635
+ | `centerCrop` | `ImageFit.Cover` | 等比缩放,填满容器,裁剪超出部分 |
636
+ | `centerInside` | `ImageFit.Contain` | 等比缩放,完整显示在容器内 |
637
+ | `fitCenter` | `ImageFit.Contain` | 等比缩放,居中显示 |
638
+ | `fitXY` | `ImageFit.Fill` | 拉伸填满容器 |
639
+ | `fitStart` | `ImageFit.Contain` | 等比缩放,靠上/靠左显示 |
640
+ | `fitEnd` | `ImageFit.Contain` | 等比缩放,靠下/靠右显示 |
641
+
642
+ ---
643
+
644
+ #### 1.3.3 Image 组件高级属性
645
+
646
+ **图片渲染模式**
647
+
648
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
649
+ |-------------|---------------|---------|---------|
650
+ | `android:alpha` | `.opacity()` | float (0-1) → number (0-1) | Android: `android:alpha="0.5"`<br/>HarmonyOS: `Image($r('app.media.image')).opacity(0.5)` |
651
+ | `android:rotation` | `.rotate()` | float → { angle: number } | Android: `android:rotation="90"`<br/>HarmonyOS: `Image($r('app.media.image')).rotate({ angle: 90 })` |
652
+ | `android:scaleX` | `.scale()` | float → { x: number } | Android: `android:scaleX="1.5"`<br/>HarmonyOS: `Image($r('app.media.image')).scale({ x: 1.5 })` |
653
+ | `android:scaleY` | `.scale()` | float → { y: number } | Android: `android:scaleY="1.5"`<br/>HarmonyOS: `Image($r('app.media.image')).scale({ y: 1.5 })` |
654
+
655
+ **图片边框与圆角**
656
+
657
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
658
+ |-------------|---------------|---------|---------|
659
+ | `android:background` | 无直接对应 | 需自定义实现 | 使用 `.border()` 和 `.borderRadius()` |
660
+ | 无直接对应 | `.borderRadius()` | 需自定义实现 | Android: 使用 ShapeDrawable<br/>HarmonyOS: `Image($r('app.media.image')).borderRadius(8)` |
661
+
662
+ **图片重复属性**
663
+
664
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
665
+ |-------------|---------------|---------|---------|
666
+ | `android:tileMode` | 无直接对应 | 需自定义实现 | 使用 `.objectRepeat()` |
667
+ | 无直接对应 | `.objectRepeat()` | 需自定义实现 | Android: `android:tileMode="repeat"`<br/>HarmonyOS: `Image($r('app.media.image')).objectRepeat(ImageRepeat.XY)` |
668
+
669
+ ---
670
+
671
+ #### 1.3.4 图片组件通用布局属性映射
672
+
673
+ 图片组件继承所有通用布局属性,参考 1.1.4 文本组件通用布局属性映射。
674
+
675
+ ---
676
+
677
+ #### 1.3.5 图片组件属性映射统计
678
+
679
+ | 映射类型 | 数量 | 占比 |
680
+ |---------|------|------|
681
+ | 直接映射 | 15 | ~40% |
682
+ | 需类型转换 | 10 | ~27% |
683
+ | 需组合实现 | 8 | ~22% |
684
+ | 无直接对应 | 5 | ~13% |
685
+ | **总计** | **38** | **100%** |
686
+
687
+ ### 1.4 选择器类组件
688
+
689
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
690
+ |-------------|------|---------------|---------|------|
691
+ | Spinner | `android.widget.Spinner` | `Select` | 直接映射 | 下拉选择框 |
692
+ | DatePicker | `android.widget.DatePicker` | `DatePicker` | 直接映射 | 日期选择器 |
693
+ | TimePicker | `android.widget.TimePicker` | `TimePicker` | 直接映射 | 时间选择器 |
694
+ | CalendarView | `android.widget.CalendarView` | `CalendarPicker` | 直接映射 | 日历视图 |
695
+ | NumberPicker | `android.widget.NumberPicker` | `TextPicker` | 配合数字数组 | 数字选择器 |
696
+
697
+ ---
698
+
699
+ #### 1.4.1 Spinner → Select 属性映射
700
+
701
+ **数据源属性**
702
+
703
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
704
+ |-------------|---------------|---------|---------|
705
+ | `android:entries` | 构造函数参数 | reference → array | Android: `android:entries="@array/items"`<br/>HarmonyOS: `Select({ options: ['item1', 'item2'] })` |
706
+ | `android:prompt` | `.placeholder()` | string → string | Android: `android:prompt="Select an item"`<br/>HarmonyOS: `Select({ placeholder: 'Select an item' })` |
707
+ | 无直接对应 | `selected` | 无 → number | Android: `setSelection(0)`<br/>HarmonyOS: `Select({ selected: 0 })` |
708
+
709
+ **显示模式属性**
710
+
711
+ | Android XML | HarmonyOS 属性 | 类型转换器 | 代码示例 |
712
+ |-------------|---------------|---------|---------|
713
+ | `android:spinnerMode` | 无直接对应 | enum → 无 | Android: `android:spinnerMode="dropdown"`<br/>HarmonyOS: Select 始终是下拉式 |
714
+ | `android:spinnerMode="dialog"` | 无直接对应 | enum → 无 | Android: `android:spinnerMode="dialog"`<br/>HarmonyOS: 需自定义实现 |
715
+
716
+ **下拉样式属性**
717
+
718
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
719
+ |-------------|---------------|---------|---------|
720
+ | `android:dropDownSelector` | 无直接对应 | reference → stateStyles | Android: `android:dropDownSelector="@drawable/selector"`<br/>HarmonyOS: `Select().stateStyles({ ... })` |
721
+ | `android:dropDownVerticalOffset` | 无直接对应 | dimension → 无 | Android: `android:dropDownVerticalOffset="10dp"`<br/>HarmonyOS: 需自定义实现 |
722
+ | `android:dropDownHorizontalOffset` | 无直接对应 | dimension → 无 | Android: `android:dropDownHorizontalOffset="10dp"`<br/>HarmonyOS: 需自定义实现 |
723
+ | `android:dropDownWidth` | 无直接对应 | dimension → 无 | Android: `android:dropDownWidth="200dp"`<br/>HarmonyOS: 需自定义实现 |
724
+ | `android:dropDownHeight` | 无直接对应 | dimension → 无 | Android: `android:dropDownHeight="300dp"`<br/>HarmonyOS: 需自定义实现 |
725
+ | `android:popupBackground` | `.backgroundColor()` | reference/color → ResourceColor | Android: `android:popupBackground="@drawable/popup_bg"`<br/>HarmonyOS: `Select().backgroundColor('#FFFFFF')` |
726
+
727
+ **文本样式属性**
728
+
729
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
730
+ |-------------|---------------|---------|---------|
731
+ | `android:gravity` | 无直接对应 | enum → 无 | Android: `android:gravity="center"`<br/>HarmonyOS: 使用 `.textAlign()` |
732
+
733
+ **程序化方法映射**
734
+
735
+ | Android 方法 | HarmonyOS 属性 | 类型转换 | 代码示例 |
736
+ |-------------|---------------|---------|---------|
737
+ | `setAdapter()` | 构造函数参数 | SpinnerAdapter → array | Android: `spinner.setAdapter(adapter)`<br/>HarmonyOS: `Select({ options: [...] })` |
738
+ | `setOnItemSelectedListener()` | `.onSelect()` | listener → callback | Android: `setOnItemSelectedListener(...)`<br/>HarmonyOS: `Select().onSelect((index: number, value?: string) => { ... })` |
739
+ | `setSelection(int)` | `selected` | int → number | Android: `setSelection(0)`<br/>HarmonyOS: 更新状态变量 `this.selectedIndex = 0` |
740
+ | `getSelectedItem()` | 无直接对应 | 无 → 状态变量 | Android: `getSelectedItem()`<br/>HarmonyOS: `this.options[this.selectedIndex]` |
741
+ | `getSelectedItemPosition()` | 无直接对应 | 无 → 状态变量 | Android: `getSelectedItemPosition()`<br/>HarmonyOS: `this.selectedIndex` |
742
+ | `setPrompt()` | `.placeholder()` | CharSequence → string | Android: `setPrompt("Select")`<br/>HarmonyOS: `Select().placeholder('Select')` |
743
+ | `setEnabled()` | `.enabled()` | boolean → boolean | Android: `setEnabled(false)`<br/>HarmonyOS: `Select().enabled(false)` |
744
+
745
+ ---
746
+
747
+ #### 1.4.2 DatePicker → DatePicker 属性映射
748
+
749
+ **日期值属性**
750
+
751
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
752
+ |-------------|---------------|---------|---------|
753
+ | `android:year` | 构造函数参数 | int → Date | Android: `android:year="2024"`<br/>HarmonyOS: `DatePicker({ selected: new Date(2024, 0, 1) })` |
754
+ | `android:month` | 构造函数参数 | int → Date | Android: `android:month="0"`<br/>HarmonyOS: `DatePicker({ selected: new Date(2024, 0, 1) })` |
755
+ | `android:day` | 构造函数参数 | int → Date | Android: `android:day="1"`<br/>HarmonyOS: `DatePicker({ selected: new Date(2024, 0, 1) })` |
756
+
757
+ **日期范围属性**
758
+
759
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
760
+ |-------------|---------------|---------|---------|
761
+ | `android:minDate` | `.minDate()` | long → Date | Android: `android:minDate="946684800000"`<br/>HarmonyOS: `DatePicker({ minDate: new Date(2000, 0, 1) })` |
762
+ | `android:maxDate` | `.maxDate()` | long → Date | Android: `android:maxDate="2524608000000"`<br/>HarmonyOS: `DatePicker({ maxDate: new Date(2050, 11, 31) })` |
763
+
764
+ **显示模式属性**
765
+
766
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
767
+ |-------------|---------------|---------|---------|
768
+ | `android:datePickerMode` | 无直接对应 | enum → 无 | Android: `android:datePickerMode="spinner"`<br/>HarmonyOS: 需自定义实现 |
769
+ | `android:calendarViewShown` | 无直接对应 | boolean → 无 | Android: `android:calendarViewShown="true"`<br/>HarmonyOS: 需自定义实现 |
770
+
771
+ **程序化方法映射**
772
+
773
+ | Android 方法 | HarmonyOS 属性 | 类型转换 | 代码示例 |
774
+ |-------------|---------------|---------|---------|
775
+ | `init()` | 构造函数参数 | (int, int, int) → Date | Android: `init(2024, 0, 1, listener)`<br/>HarmonyOS: `DatePicker({ selected: new Date(2024, 0, 1) })` |
776
+ | `updateDate()` | 更新状态变量 | (int, int, int) → Date | Android: `updateDate(2024, 0, 1)`<br/>HarmonyOS: `this.selectedDate = new Date(2024, 0, 1)` |
777
+ | `getYear()` | 无直接对应 | 无 → 状态变量 | Android: `getYear()`<br/>HarmonyOS: `this.selectedDate.getFullYear()` |
778
+ | `getMonth()` | 无直接对应 | 无 → 状态变量 | Android: `getMonth()`<br/>HarmonyOS: `this.selectedDate.getMonth()` |
779
+ | `getDayOfMonth()` | 无直接对应 | 无 → 状态变量 | Android: `getDayOfMonth()`<br/>HarmonyOS: `this.selectedDate.getDate()` |
780
+ | `setOnDateChangedListener()` | `.onChange()` | listener → callback | Android: `setOnDateChangedListener(...)`<br/>HarmonyOS: `DatePicker().onChange((value: Date) => { ... })` |
781
+
782
+ ---
783
+
784
+ #### 1.4.3 TimePicker → TimePicker 属性映射
785
+
786
+ **时间值属性**
787
+
788
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
789
+ |-------------|---------------|---------|---------|
790
+ | `android:hour` | 构造函数参数 | int → number | Android: `android:hour="12"`<br/>HarmonyOS: `TimePicker({ selected: new Date(2024, 0, 1, 12, 0, 0) })` |
791
+ | `android:minute` | 构造函数参数 | int → number | Android: `android:minute="30"`<br/>HarmonyOS: `TimePicker({ selected: new Date(2024, 0, 1, 12, 30, 0) })` |
792
+ | `android:second` | 构造函数参数 | int → number | Android: `android:second="0"`<br/>HarmonyOS: `TimePicker({ selected: new Date(2024, 0, 1, 12, 30, 0) })` |
793
+
794
+ **时间格式属性**
795
+
796
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
797
+ |-------------|---------------|---------|---------|
798
+ | `android:format` | 无直接对应 | string → 无 | Android: `android:format="24"`<br/>HarmonyOS: 需自定义实现 |
799
+ | `android:is24HourView` | 无直接对应 | boolean → 无 | Android: `android:is24HourView="true"`<br/>HarmonyOS: 需自定义实现 |
800
+
801
+ **程序化方法映射**
802
+
803
+ | Android 方法 | HarmonyOS 属性 | 类型转换 | 代码示例 |
804
+ |-------------|---------------|---------|---------|
805
+ | `setOnTimeChangedListener()` | `.onChange()` | listener → callback | Android: `setOnTimeChangedListener(...)`<br/>HarmonyOS: `TimePicker().onChange((value: Date) => { ... })` |
806
+ | `getHour()` | 无直接对应 | 无 → 状态变量 | Android: `getHour()`<br/>HarmonyOS: `this.selectedDate.getHours()` |
807
+ | `getMinute()` | 无直接对应 | 无 → 状态变量 | Android: `getMinute()`<br/>HarmonyOS: `this.selectedDate.getMinutes()` |
808
+ | `getSecond()` | 无直接对应 | 无 → 状态变量 | Android: `getSecond()`<br/>HarmonyOS: `this.selectedDate.getSeconds()` |
809
+
810
+ ---
811
+
812
+ #### 1.4.4 CalendarView → CalendarPicker 属性映射
813
+
814
+ **日期选择属性**
815
+
816
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
817
+ |-------------|---------------|---------|---------|
818
+ | `android:minDate` | `.minDate()` | long → Date | Android: `android:minDate="946684800000"`<br/>HarmonyOS: `CalendarPicker({ minDate: new Date(2000, 0, 1) })` |
819
+ | `android:maxDate` | `.maxDate()` | long → Date | Android: `android:maxDate="2524608000000"`<br/>HarmonyOS: `CalendarPicker({ maxDate: new Date(2050, 11, 31) })` |
820
+ | `android:firstDayOfWeek` | 无直接对应 | int → 无 | Android: `android:firstDayOfWeek="1"`<br/>HarmonyOS: 需自定义实现 |
821
+
822
+ **显示属性**
823
+
824
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
825
+ |-------------|---------------|---------|---------|
826
+ | `android:shownWeekCount` | 无直接对应 | int → 无 | Android: `android:shownWeekCount="4"`<br/>HarmonyOS: 需自定义实现 |
827
+ | `android:weekNumberColor` | 无直接对应 | color → 无 | Android: `android:weekNumberColor="#FF0000"`<br/>HarmonyOS: 需自定义实现 |
828
+
829
+ **程序化方法映射**
830
+
831
+ | Android 方法 | HarmonyOS 属性 | 类型转换 | 代码示例 |
832
+ |-------------|---------------|---------|---------|
833
+ | `setOnDateChangeListener()` | `.onChange()` | listener → callback | Android: `setOnDateChangeListener(...)`<br/>HarmonyOS: `CalendarPicker().onChange((value: Date) => { ... })` |
834
+ | `setDate()` | 更新状态变量 | Calendar → Date | Android: `setDate(calendar)`<br/>HarmonyOS: `this.selectedDate = calendar.getTime()` |
835
+
836
+ ---
837
+
838
+ #### 1.4.5 NumberPicker → TextPicker 属性映射
839
+
840
+ **数据源属性**
841
+
842
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
843
+ |-------------|---------------|---------|---------|
844
+ | `android:minValue` | `range` | int → [number, number] | Android: `android:minValue="0"`<br/>HarmonyOS: `TextPicker({ range: [0, 100] })` |
845
+ | `android:maxValue` | `range` | int → [number, number] | Android: `android:maxValue="100"`<br/>HarmonyOS: `TextPicker({ range: [0, 100] })` |
846
+ | `android:wrapSelectorWheel` | 无直接对应 | boolean → 无 | Android: `android:wrapSelectorWheel="true"`<br/>HarmonyOS: 需自定义实现 |
847
+
848
+ **显示值属性**
849
+
850
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
851
+ |-------------|---------------|---------|---------|
852
+ | `android:displayedValues` | 构造函数参数 | array → array | Android: `android:displayedValues="@array/numbers"`<br/>HarmonyOS: `TextPicker({ range: [1, 2, 3, 4, 5] })` |
853
+
854
+ **程序化方法映射**
855
+
856
+ | Android 方法 | HarmonyOS 属性 | 类型转换 | 代码示例 |
857
+ |-------------|---------------|---------|---------|
858
+ | `setDisplayedValues()` | 构造函数参数 | array → array | Android: `setDisplayedValues(values)`<br/>HarmonyOS: `TextPicker({ range: values })` |
859
+ | `setOnValueChangedListener()` | `.onChange()` | listener → callback | Android: `setOnValueChangedListener(...)`<br/>HarmonyOS: `TextPicker().onChange((value: string) => { ... })` |
860
+ | `setValue()` | 更新状态变量 | int → number | Android: `setValue(50)`<br/>HarmonyOS: `this.selectedValue = 50` |
861
+ | `getValue()` | 无直接对应 | 无 → 状态变量 | Android: `getValue()`<br/>HarmonyOS: `this.selectedValue` |
862
+
863
+ ---
864
+
865
+ #### 1.4.6 选择器组件属性映射统计
866
+
867
+ | 映射类型 | 数量 | 占比 |
868
+ |---------|------|------|
869
+ | 直接映射 | 25 | ~45% |
870
+ | 需类型转换 | 15 | ~27% |
871
+ | 需组合实现 | 10 | ~18% |
872
+ | 无直接对应 | 5 | ~10% |
873
+ | **总计** | **55** | **100%** |
874
+
875
+ ---
876
+
877
+ ### 1.5 进度与评分类组件
878
+
879
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
880
+ |-------------|------|---------------|---------|------|
881
+ | ProgressBar | `android.widget.ProgressBar` | `Progress` | 直接映射 | 进度条 |
882
+ | SeekBar | `android.widget.SeekBar` | `Slider` | 直接映射 | 可拖动进度条 |
883
+ | RatingBar | `android.widget.RatingBar` | `Rating` | 直接映射 | 评分条 |
884
+ | ContentLoadingProgressBar | `android.widget.ContentLoadingProgressBar` | `Progress` + `LoadingProgress` | 组合实现 | 内容加载进度条 |
885
+
886
+ ---
887
+
888
+ #### 1.5.1 ProgressBar → Progress 属性映射
889
+
890
+ **进度值属性**
891
+
892
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
893
+ |-------------|---------------|---------|---------|
894
+ | `android:max` | 构造函数参数 | int → number | Android: `android:max="100"`<br/>HarmonyOS: `Progress({ value: 50, total: 100 })` |
895
+ | `android:progress` | 构造函数参数 | int → number | Android: `android:progress="50"`<br/>HarmonyOS: `Progress({ value: 50, total: 100 })` |
896
+ | `android:secondaryProgress` | 无直接对应 | int → 无 | Android: `android:secondaryProgress="75"`<br/>HarmonyOS: 需自定义实现 |
897
+
898
+ **不确定模式属性**
899
+
900
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
901
+ |-------------|---------------|---------|---------|
902
+ | `android:indeterminate` | 构造函数参数 | boolean → boolean | Android: `android:indeterminate="true"`<br/>HarmonyOS: `Progress({ value: 0, total: 100, type: ProgressType.Ring })` |
903
+ | `android:indeterminateOnly` | 无直接对应 | boolean → 无 | Android: `android:indeterminateOnly="true"`<br/>HarmonyOS: 需自定义实现 |
904
+ | `android:indeterminateDuration` | 无直接对应 | int → 无 | Android: `android:indeterminateDuration="2000"`<br/>HarmonyOS: 需自定义实现 |
905
+ | `android:indeterminateBehavior` | 无直接对应 | enum → 无 | Android: `android:indeterminateBehavior="repeat"`<br/>HarmonyOS: 需自定义实现 |
906
+
907
+ **样式属性**
908
+
909
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
910
+ |-------------|---------------|---------|---------|
911
+ | `android:progressDrawable` | 无直接对应 | reference → 无 | Android: `android:progressDrawable="@drawable/progress"`<br/>HarmonyOS: 需自定义实现 |
912
+ | `android:indeterminateDrawable` | 无直接对应 | reference → 无 | Android: `android:indeterminateDrawable="@drawable/indeterminate"`<br/>HarmonyOS: 需自定义实现 |
913
+ | `android:progressTint` | `.color()` | color → ResourceColor | Android: `android:progressTint="#FF6200"`<br/>HarmonyOS: `Progress({ value: 50, total: 100 }).color('#FF6200')` |
914
+ | `android:progressTintMode` | 无直接对应 | enum → 无 | Android: `android:progressTintMode="src_in"`<br/>HarmonyOS: 需自定义实现 |
915
+ | `android:secondaryProgressTint` | 无直接对应 | color → 无 | Android: `android:secondaryProgressTint="#00FF00"`<br/>HarmonyOS: 需自定义实现 |
916
+ | `android:progressBackgroundTint` | `.backgroundColor()` | color → ResourceColor | Android: `android:progressBackgroundTint="#E0E0E0"`<br/>HarmonyOS: `Progress({ value: 50, total: 100 }).backgroundColor('#E0E0E0')` |
917
+
918
+ **程序化方法映射**
919
+
920
+ | Android 方法 | HarmonyOS 属性 | 类型转换 | 代码示例 |
921
+ |-------------|---------------|---------|---------|
922
+ | `setMax(int max)` | 构造函数参数 | int → number | Android: `progressBar.setMax(100)`<br/>HarmonyOS: `Progress({ value: this.progress, total: 100 })` |
923
+ | `getMax()` | 无直接对应 | void → number | Android: `int max = progressBar.getMax()`<br/>HarmonyOS: 使用状态变量 `this.total` |
924
+ | `setProgress(int progress)` | 构造函数参数 | int → number | Android: `progressBar.setProgress(50)`<br/>HarmonyOS: 更新状态变量 `this.progress = 50` |
925
+ | `getProgress()` | 无直接对应 | void → number | Android: `int progress = progressBar.getProgress()`<br/>HarmonyOS: 使用状态变量 `this.progress` |
926
+ | `incrementProgressBy(int delta)` | 无直接对应 | int → 无 | Android: `progressBar.incrementProgressBy(5)`<br/>HarmonyOS: `this.progress += 5` |
927
+ | `setSecondaryProgress(int)` | 无直接对应 | int → 无 | Android: `progressBar.setSecondaryProgress(75)`<br/>HarmonyOS: 需自定义实现 |
928
+ | `getSecondaryProgress()` | 无直接对应 | void → int | Android: `int sec = progressBar.getSecondaryProgress()`<br/>HarmonyOS: 需自定义实现 |
929
+ | `setIndeterminate(boolean)` | 构造函数参数 | boolean → ProgressType | Android: `progressBar.setIndeterminate(true)`<br/>HarmonyOS: `Progress({ type: ProgressType.Ring })` |
930
+ | `isIndeterminate()` | 无直接对应 | void → boolean | Android: `boolean isIndet = progressBar.isIndeterminate()`<br/>HarmonyOS: 使用状态变量 |
931
+
932
+ **ProgressType 枚举值映射**
933
+
934
+ | Android Style | HarmonyOS ProgressType | 说明 |
935
+ |-----------------|-------------------|------|
936
+ | `Widget.ProgressBar` (circular) | `ProgressType.Ring` | 圆形进度条 |
937
+ | `Widget.ProgressBar.Horizontal` | `ProgressType.Linear` | 线性进度条 |
938
+
939
+ ---
940
+
941
+ #### 1.5.2 SeekBar → Slider 属性映射
942
+
943
+ **进度值属性**
944
+
945
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
946
+ |-------------|---------------|---------|---------|
947
+ | `android:max` | 构造函数参数 | int → number | Android: `android:max="100"`<br/>HarmonyOS: `Slider({ value: 50, min: 0, max: 100 })` |
948
+ | `android:progress` | 构造函数参数 | int → number | Android: `android:progress="50"`<br/>HarmonyOS: `Slider({ value: 50, min: 0, max: 100 })` |
949
+ | `android:min` | 构造函数参数 | int → number | Android: `android:min="0"`<br/>HarmonyOS: `Slider({ value: 50, min: 0, max: 100 })` |
950
+ | `android:secondaryProgress` | 无直接对应 | int → 无 | Android: `android:secondaryProgress="75"`<br/>HarmonyOS: 需自定义实现 |
951
+
952
+ **视觉外观属性**
953
+
954
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
955
+ |-------------|---------------|---------|---------|
956
+ | `android:thumb` | 无直接对应 | drawable → 无 | Android: `android:thumb="@drawable/thumb"`<br/>HarmonyOS: 需自定义实现 |
957
+ | `android:thumbTint` | 无直接对应 | color → 无 | Android: `android:thumbTint="#FF0000"`<br/>HarmonyOS: 需自定义实现 |
958
+ | `android:thumbTintMode` | 无直接对应 | enum → 无 | Android: `android:thumbTintMode="src_in"`<br/>HarmonyOS: 需自定义实现 |
959
+ | `android:thumbOffset` | 无直接对应 | int → 无 | Android: `android:thumbOffset="10"`<br/>HarmonyOS: 需自定义实现 |
960
+ | `android:track` | `.trackColor()` | drawable → ResourceColor | Android: `android:track="@drawable/track"`<br/>HarmonyOS: `Slider({ value: 50 }).trackColor('#CCCCCC')` |
961
+ | `android:progressTint` | `.selectedColor()` | color → ResourceColor | Android: `android:progressTint="#FF6200"`<br/>HarmonyOS: `Slider({ value: 50 }).selectedColor('#FF6200')` |
962
+ | `android:progressTintMode` | 无直接对应 | enum → 无 | Android: `android:progressTintMode="src_in"`<br/>HarmonyOS: 需自定义实现 |
963
+ | `android:progressBackgroundTint` | `.trackColor()` | color → ResourceColor | Android: `android:progressBackgroundTint="#E0E0E0"`<br/>HarmonyOS: `Slider({ value: 50 }).trackColor('#E0E0E0')` |
964
+ | `android:secondaryProgressTint` | 无直接对应 | color → 无 | Android: `android:secondaryProgressTint="#00FF00"`<br/>HarmonyOS: 需自定义实现 |
965
+
966
+ **交互属性**
967
+
968
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
969
+ |-------------|---------------|---------|---------|
970
+ | `android:splitTrack` | 无直接对应 | boolean → 无 | Android: `android:splitTrack="false"`<br/>HarmonyOS: 需自定义实现 |
971
+ | `android:mirrorForRtl` | 无直接对应 | boolean → 无 | Android: `android:mirrorForRtl="true"`<br/>HarmonyOS: 需自定义实现 |
972
+ | `android:isIndicator` | 无直接对应 | boolean → 无 | Android: `android:isIndicator="true"`<br/>HarmonyOS: 需自定义实现 |
973
+
974
+ **程序化方法映射**
975
+
976
+ | Android 方法 | HarmonyOS 属性 | 类型转换 | 代码示例 |
977
+ |-------------|---------------|---------|---------|
978
+ | `getMax()` | 无直接对应 | void → number | Android: `int max = seekBar.getMax()`<br/>HarmonyOS: 使用状态变量 `this.max` |
979
+ | `setMax(int max)` | 构造函数参数 | int → number | Android: `seekBar.setMax(100)`<br/>HarmonyOS: 更新状态变量 `this.max = 100` |
980
+ | `getProgress()` | 无直接对应 | void → number | Android: `int progress = seekBar.getProgress()`<br/>HarmonyOS: 使用状态变量 `this.progress` |
981
+ | `setProgress(int progress)` | 构造函数参数 | int → number | Android: `seekBar.setProgress(50)`<br/>HarmonyOS: 更新状态变量 `this.progress = 50` |
982
+ | `incrementProgressBy(int delta)` | 无直接对应 | int → 无 | Android: `seekBar.incrementProgressBy(5)`<br/>HarmonyOS: `this.progress += 5` |
983
+ | `getMin()` | 无直接对应 | void → number | Android: `int min = seekBar.getMin()`<br/>HarmonyOS: 使用状态变量 `this.min` |
984
+ | `setMin(int min)` | 构造函数参数 | int → number | Android: `seekBar.setMin(0)`<br/>HarmonyOS: 更新状态变量 `this.min = 0` |
985
+
986
+ **事件监听器映射**
987
+
988
+ | Android 监听器 | HarmonyOS 属性 | 类型转换 | 代码示例 |
989
+ |-------------|---------------|---------|---------|
990
+ | `setOnSeekBarChangeListener()` | `.onChange()` | listener → callback | Android: `setOnSeekBarChangeListener(...)`<br/>HarmonyOS: `Slider().onChange((value: number) => { ... })` |
991
+
992
+ ---
993
+
994
+ #### 1.5.3 RatingBar → Rating 属性映射
995
+
996
+ **评分值属性**
997
+
998
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
999
+ |-------------|---------------|---------|---------|
1000
+ | `android:numStars` | 构造函数参数 | int → number | Android: `android:numStars="5"`<br/>HarmonyOS: `Rating({ rating: 3.5, starNum: 5 })` |
1001
+ | `android:rating` | 构造函数参数 | float → number | Android: `android:rating="3.5"`<br/>HarmonyOS: `Rating({ rating: 3.5, starNum: 5 })` |
1002
+ | `android:stepSize` | 构造函数参数 | float → number | Android: `android:stepSize="0.5"`<br/>HarmonyOS: `Rating({ rating: 3.5, stepSize: 0.5 })` |
1003
+ | `android:isIndicator` | 无直接对应 | boolean → 无 | Android: `android:isIndicator="true"`<br/>HarmonyOS: 使用 `.enabled(false)` |
1004
+
1005
+ **程序化方法映射**
1006
+
1007
+ | Android 方法 | HarmonyOS 属性 | 类型转换 | 代码示例 |
1008
+ |-------------|---------------|---------|---------|
1009
+ | `setNumStars(int numStars)` | 构造函数参数 | int → number | Android: `ratingBar.setNumStars(5)`<br/>HarmonyOS: `Rating({ rating: this.rating, starNum: 5 })` |
1010
+ | `getNumStars()` | 无直接对应 | void → int | Android: `int numStars = ratingBar.getNumStars()`<br/>HarmonyOS: 使用状态变量 `this.starNum` |
1011
+ | `setRating(float rating)` | 构造函数参数 | float → number | Android: `ratingBar.setRating(3.5f)`<br/>HarmonyOS: 更新状态变量 `this.rating = 3.5` |
1012
+ | `getRating()` | 无直接对应 | void → float | Android: `float rating = ratingBar.getRating()`<br/>HarmonyOS: 使用状态变量 `this.rating` |
1013
+ | `setStepSize(float stepSize)` | 构造函数参数 | float → number | Android: `ratingBar.setStepSize(0.5f)`<br/>HarmonyOS: `Rating({ rating: this.rating, stepSize: 0.5 })` |
1014
+ | `getStepSize()` | 无直接对应 | void → float | Android: `float stepSize = ratingBar.getStepSize()`<br/>HarmonyOS: 使用状态变量 `this.stepSize` |
1015
+ | `setIsIndicator(boolean)` | 无直接对应 | boolean → 无 | Android: `ratingBar.setIsIndicator(true)`<br/>HarmonyOS: 使用 `.enabled(false)` |
1016
+ | `isIndicator()` | 无直接对应 | void → boolean | Android: `boolean isInd = ratingBar.isIndicator()`<br/>HarmonyOS: 使用状态变量 |
1017
+
1018
+ **事件监听器映射**
1019
+
1020
+ | Android 监听器 | HarmonyOS 属性 | 类型转换 | 代码示例 |
1021
+ |-------------|---------------|---------|---------|
1022
+ | `setOnRatingBarChangeListener()` | `.onChange()` | listener → callback | Android: `setOnRatingBarChangeListener(...)`<br/>HarmonyOS: `Rating().onChange((value: number) => { ... })` |
1023
+
1024
+ ---
1025
+
1026
+ #### 1.5.4 ContentLoadingProgressBar → Progress + LoadingProgress 组合实现
1027
+
1028
+ **组合功能映射**
1029
+
1030
+ | Android 功能 | HarmonyOS 实现 | 代码示例 |
1031
+ |-------------|---------------|---------|
1032
+ | 进度显示 | `Progress` 组件 | Android: `ProgressBar`<br/>HarmonyOS: `Progress({ value: this.progress, total: 100 })` |
1033
+ | 加载动画 | `LoadingProgress` 组件 | Android: `ContentLoadingProgressBar`<br/>HarmonyOS: `LoadingProgress()` |
1034
+
1035
+ ---
1036
+
1037
+ #### 1.5.5 进度与评分类组件属性映射统计
1038
+
1039
+ | 映射类型 | 数量 | 占比 |
1040
+ |---------|------|------|
1041
+ | 直接映射 | 30 | ~40% |
1042
+ | 需类型转换 | 20 | ~27% |
1043
+ | 需组合实现 | 15 | ~20% |
1044
+ | 无直接对应 | 10 | ~13% |
1045
+ | **总计** | **75** | **100%** |
1046
+
1047
+ ### 1.6 搜索类组件
1048
+
1049
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
1050
+ |-------------|------|---------------|---------|------|
1051
+ | SearchView | `android.widget.SearchView` | `Search` | 直接映射 | 搜索视图 |
1052
+ | SearchBar | `android.widget.SearchBar` | `Search` | 直接映射 | 搜索栏 |
1053
+
1054
+ ---
1055
+
1056
+ #### 1.6.1 SearchView/SearchBar → Search 属性映射
1057
+
1058
+ **搜索值属性**
1059
+
1060
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1061
+ |-------------|---------------|---------|---------|
1062
+ | `android:queryHint` | `.placeholder()` | string → string | Android: `android:queryHint="Search..."`<br/>HarmonyOS: `Search({ value: '' }).placeholder('Search...')` |
1063
+ | `android:query` | 构造函数参数 | string → string | Android: `android:query="search"`<br/>HarmonyOS: `Search({ value: 'search' })` |
1064
+ | `android:iconifiedByDefault` | 无直接对应 | boolean → 无需自定义实现 | Android: `android:iconifiedByDefault="true"`<br/>HarmonyOS: 需自定义实现 |
1065
+
1066
+ **搜索按钮属性**
1067
+
1068
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1069
+ |-------------|---------------|---------|---------|
1070
+ | `android:searchIcon` | 无直接对应 | drawable → 需自定义实现 | Android: `android:searchIcon="@drawable/ic_search"`<br/>HarmonyOS: 需自定义实现 |
1071
+ | `android:closeIcon` | 无直接对应 | drawable → 需自定义实现 | Android: `android:closeIcon="@drawable/ic_close"`<br/>HarmonyOS: 需自定义实现 |
1072
+ | `android:goIcon` | 无直接对应 | drawable → 需自定义实现 | Android: `android:goIcon="@drawable/ic_go"`<br/>HarmonyOS: 需自定义实现 |
1073
+ | `android:voiceIcon` | 无直接对应 | drawable → 需自定义实现 | Android: `android:voiceIcon="@drawable/ic_mic"`<br/>HarmonyOS: 需自定义实现 |
1074
+ | `android:commitIcon` | 无直接对应 | drawable → 需自定义实现 | Android: `android:commitIcon="@drawable/ic_commit"`<br/>HarmonyOS: 需自定义实现 |
1075
+
1076
+ **搜索选项属性**
1077
+
1078
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1079
+ |-------------|---------------|---------|---------|
1080
+ | `android:searchSuggestAuthority` | 无直接对应 | string → 需自定义实现 | Android: `android:searchSuggestAuthority="com.example"`<br/>HarmonyOS: 需自定义实现 |
1081
+ | `android:searchSuggestSelection` | 无直接对应 | string → 需自定义实现 | Android: `android:searchSuggestSelection="query"`<br/>HarmonyOS: 需自定义实现 |
1082
+ | `android:searchSuggestThreshold` | 无直接对应 | int → 需自定义实现 | Android: `android:searchSuggestThreshold="1"`<br/>HarmonyOS: 需自定义实现 |
1083
+
1084
+ **输入法属性**
1085
+
1086
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1087
+ |-------------|---------------|---------|---------|
1088
+ | `android:imeOptions` | 无直接对应 | enum → 需自定义实现 | Android: `android:imeOptions="actionSearch"`<br/>HarmonyOS: 需自定义实现 |
1089
+ | `android:inputType` | 无直接对应 | enum → 需自定义实现 | Android: `android:inputType="text"`<br/>HarmonyOS: 需自定义实现 |
1090
+
1091
+ **程序化方法映射**
1092
+
1093
+ | Android 方法 | HarmonyOS 属性 | 类型转换 | 代码示例 |
1094
+ |-------------|---------------|---------|---------|
1095
+ | `setQuery()` | 更新状态变量 | string → string | Android: `searchView.setQuery("search")`<br/>HarmonyOS: 更新状态变量 `this.searchValue = "search"` |
1096
+ | `getQuery()` | 无直接对应 | void → string | Android: `String query = searchView.getQuery()`<br/>HarmonyOS: 使用状态变量 `this.searchValue` |
1097
+ | `setOnQueryTextListener()` | `.onChange()` | listener → callback | Android: `setOnQueryTextListener(...)`<br/>HarmonyOS: `Search().onChange((value: string) => { ... })` |
1098
+ | `setOnCloseListener()` | 无直接对应 | listener → 需自定义实现 | Android: `setOnCloseListener(...)`<br/>HarmonyOS: 需自定义实现 |
1099
+ | `setOnSearchClickListener()` | 无直接对应 | listener → 需自定义实现 | Android: `setOnSearchClickListener(...)`<br/>HarmonyOS: 需自定义实现 |
1100
+
1101
+ **事件监听器映射**
1102
+
1103
+ | Android 监听器 | HarmonyOS 属性 | 类型转换 | 代码示例 |
1104
+ |-------------|---------------|---------|---------|
1105
+ | `OnQueryTextListener` | `.onChange()` | listener → callback | Android: `setOnQueryTextListener(...)`<br/>HarmonyOS: `Search().onChange((value: string) => { ... })` |
1106
+ | `OnCloseListener` | 无直接对应 | listener → 需自定义实现 | Android: `setOnCloseListener(...)`<br/>HarmonyOS: 需自定义实现 |
1107
+ | `OnSuggestionListener` | 无直接对应 | listener → 需自定义实现 | Android: `setOnSuggestionListener(...)`<br/>HarmonyOS: 需自定义实现 |
1108
+
1109
+ ---
1110
+
1111
+ #### 1.6.2 搜索组件属性映射统计
1112
+
1113
+ | 映射类型 | 数量 | 占比 |
1114
+ |---------|------|------|
1115
+ | 直接映射 | 10 | ~35% |
1116
+ | 需类型转换 | 5 | ~17% |
1117
+ | 需组合实现 | 8 | ~28% |
1118
+ | 无直接对应 | 6 | ~20% |
1119
+ | **总计** | **29** | **100%** |
1120
+
1121
+ ### 1.7 视频与媒体类组件
1122
+
1123
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
1124
+ |-------------|------|---------------|---------|------|
1125
+ | VideoView | `android.widget.VideoView` | `Video` | 直接映射 | 视频播放视图 |
1126
+ | MediaController | `android.widget.MediaController` | 自定义组合 | Row + 控制按钮 | 媒体控制器 |
1127
+ | Space | `android.widget.Space` | `Row`/`Column` 空子项 | 布局技巧 | 空白占位 |
1128
+
1129
+ ---
1130
+
1131
+ #### 1.7.1 VideoView → Video 属性映射
1132
+
1133
+ **视频源属性**
1134
+
1135
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1136
+ |-------------|---------------|---------|---------|
1137
+ | `android:videoPath` | 构造函数参数 | String → string | Android: `android:videoPath="/sdcard/video.mp4"`<br/>HarmonyOS: `Video({ src: '/sdcard/video.mp4' })` |
1138
+ | 无直接对应 | `previewUri` | 无 → Resource | Android: 无<br/>HarmonyOS: `Video({ previewUri: $r('app.media.preview') })` |
1139
+
1140
+ **视频播放控制属性**
1141
+
1142
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1143
+ |-------------|---------------|---------|---------|
1144
+ | 无直接对应 | `autoPlay` | 无 → boolean | Android: 需手动调用 start()<br/>HarmonyOS: `Video({ src: 'video.mp4' }).autoPlay(true)` |
1145
+ | 无直接对应 | `loop` | 无 → boolean | Android: `setLooping(true)`<br/>HarmonyOS: `Video({ src: 'video.mp4' }).loop(true)` |
1146
+ | 无直接对应 | `muted`` | 无 → boolean | Android: `setVolume(0)`<br/>HarmonyOS: `Video({ src: 'video.mp4' }).muted(true)` |
1147
+ | 无直接对应 | `controls` | 无 → boolean | Android: 使用 MediaController<br/>HarmonyOS: `Video({ src: 'video.mp4' }).controls(true)` |
1148
+ | 无直接对应 | `objectFit` | 无 → ImageFit | Android: `setScaleType(ScaleType.FIT_CENTER)`<br/>HarmonyOS: `Video({ src: 'video.mp4' }).objectFit(ImageFit.Contain)` |
1149
+
1150
+ **视频缩放类型映射**
1151
+
1152
+ | Android ScaleType | HarmonyOS ImageFit | 说明 |
1153
+ |-----------------|-------------------|------|
1154
+ | `FIT_CENTER` | `ImageFit.Contain` | 等比缩放,完整显示 |
1155
+ | `CENTER_CROP` | `ImageFit.Cover` | 等比缩放,填满容器 |
1156
+ | `FIT_XY` | `ImageFit.Fill` | 拉伸填满容器 |
1157
+ | `CENTER` | `ImageFit.None` | 不缩放,居中显示 |
1158
+
1159
+ **视频事件属性**
1160
+
1161
+ | Android 监听器 | HarmonyOS 属性 | 类型转换 | 代码示例 |
1162
+ |-------------|---------------|---------|---------|
1163
+ | `OnPreparedListener` | `.onPrepared()` | 监听器 → 回调函数 | Android: `setOnPreparedListener(...)`<br/>HarmonyOS: `Video({ src: 'video.mp4' }).onPrepared((event) => { ... })` |
1164
+ | `OnCompletionListener` | `.onFinish()` | 监听器 → 回调函数 | Android: `setOnCompletionListener(...)`<br/>HarmonyOS: `Video({ src: 'video.mp4' }).onFinish(() => { ... })` |
1165
+ | `OnErrorListener` | `.onError()` | 监听器 → 回调函数 | Android: `setOnErrorListener(...)`<br/>HarmonyOS: `Video({ src: 'video.mp4' }).onError(() => { ... })` |
1166
+ | `OnInfoListener` | `.onUpdate()` | 监听器 → 回调函数 | Android: `setOnInfoListener(...)`<br/>HarmonyOS: `Video({ src: 'video.mp4' }).onUpdate((event) => { ... })` |
1167
+ | 无直接对应 | `.onStart()` | 无 → 回调函数 | Android: 无<br/>HarmonyOS: `Video({ src: 'video.mp4' }).onStart(() => { ... })` |
1168
+ | 无直接对应 | `.onPause()` | 无 → 回调函数 | Android: 无<br/>HarmonyOS: `Video({ src: 'video.mp4' }).onPause(() => { ... })` |
1169
+
1170
+ **VideoController 方法映射**
1171
+
1172
+ | Android 方法 | HarmonyOS 方法 | 类型转换 | 代码示例 |
1173
+ |-------------|---------------|---------|---------|
1174
+ | `start()` | `controller.start()` | void → void | Android: `videoView.start()`<br/>HarmonyOS: `this.controller.start()` |
1175
+ | `pause()` | `controller.pause()` | void → void | Android: `videoView.pause()`<br/>HarmonyOS: `this.controller.pause()` |
1176
+ | `stopPlayback()` | `controller.stop()` | void → void | Android: `videoView.stopPlayback()`<br/>HarmonyOS: `this.controller.stop()` |
1177
+ | `seekTo(int)` | `controller.setCurrentTime()` | int → (number, SeekMode) | Android: `videoView.seekTo(5000)`<br/>HarmonyOS: `this.controller.setCurrentTime(5000, SeekMode.Accurate)` |
1178
+ | `resume()` | `controller.start()` | void → void | Android: `videoView.resume()`<br/>HarmonyOS: `this.controller.start()` |
1179
+ | `suspend()` | `controller.pause()` | void → void | Android: `videoView.suspend()`<br/>HarmonyOS: `this.controller.pause()` |
1180
+ | `isPlaying()` | 无直接对应 | 需状态管理 | 使用 `@State` 变量 |
1181
+ | `getDuration()` | 无直接对应 | 需状态管理 | 使用 `@State` 变量 |
1182
+ | `getCurrentPosition()` | 无直接对应 | 需状态管理 | 使用 `@State` 变量 |
1183
+
1184
+ **SeekMode 枚举值映射**
1185
+
1186
+ | Android SeekMode | HarmonyOS SeekMode | 说明 |
1187
+ |-----------------|-------------------|------|
1188
+ | `SEEK_CLOSEST_SYNC` | `SeekMode.Accurate` | 精确定位 |
1189
+ | `SEEK_PREVIOUS_SYNC` | `SeekMode.PreviousKeyFrame` | 定位到前一个关键帧 |
1190
+ | `SEEK_NEXT_SYNC` | `SeekMode.NextKeyFrame` | 定位到后一个关键帧 |
1191
+
1192
+ **视频其他属性**
1193
+
1194
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1195
+ |-------------|---------------|---------|---------|
1196
+ | `android:layout_width` | `.width()` | dp → vp | Android: `android:layout_width="match_parent"`<br/>HarmonyOS: `Video({ src: 'video.mp4' }).width('100%')` |
1197
+ | `android:layout_height` | `.height()` | dp → vp | Android: `android:layout_height="200dp"`<br/>HarmonyOS: `Video({ src: 'video.mp4' }).height(200)` |
1198
+ | 无直接对应 | `controller` | 无 → VideoController | Android: 无<br/>HarmonyOS: `Video({ src: 'video.mp4', controller: this.controller })` |
1199
+
1200
+ ---
1201
+
1202
+ #### 1.7.2 MediaController → 自定义组合实现
1203
+
1204
+ **MediaController 功能映射**
1205
+
1206
+ | Android 功能 | HarmonyOS 实现 | 代码示例 |
1207
+ |-------------|---------------|---------|
1208
+ | 播放/暂停按钮 | `Button` + `onClick` | 使用 `controller.start()` / `controller.pause()` |
1209
+ | 进度条 | `Slider` + `onChange` | 使用 `controller.setCurrentTime()` |
1210
+ | 时间显示 | `Text` + 状态变量 | 使用 `onUpdate` 事件更新 |
1211
+ | 全屏按钮 | `Button` + `onClick` | 使用窗口 API 切换全屏 |
1212
+
1213
+ **组合示例:**
1214
+ ```typescript
1215
+ // Android
1216
+ <VideoView
1217
+ android:id="@+id/videoView"
1218
+ android:layout_width="match_parent"
1219
+ android:layout_height="200dp" />
1220
+ <MediaController
1221
+ android:id="@+id/mediaController"
1222
+ android:layout_width="match_parent"
1223
+ android:layout_height="wrap_content"
1224
+ android:layout_alignParentBottom="true"
1225
+ app:mediaController="@id/videoView" />
1226
+
1227
+ // HarmonyOS
1228
+ @State isPlaying: boolean = false
1229
+ @State currentTime: number = 0
1230
+ @State duration: number = 0
1231
+
1232
+ Column() {
1233
+ Video({
1234
+ src: 'video.mp4',
1235
+ controller: this.videoController
1236
+ })
1237
+ .width('100%')
1238
+ .height(200)
1239
+ .onUpdate((event) => {
1240
+ this.currentTime = event.time;
1241
+ })
1242
+ .onPrepared((event) => {
1243
+ this.duration = event?.duration || 0;
1244
+ })
1245
+
1246
+ Row() {
1247
+ Button('Play')
1248
+ .onClick(() => {
1249
+ this.videoController.start();
1250
+ this.isPlaying = true;
1251
+ })
1252
+ Button('Pause')
1253
+ .onClick(() => {
1254
+ this.videoController.pause();
1255
+ this.isPlaying = false;
1256
+ })
1257
+ Text(`${this.currentTime / 1000}s / ${this.duration / 1000}s`)
1258
+ }
1259
+ }
1260
+ ```
1261
+
1262
+ ---
1263
+
1264
+ #### 1.7.3 视频组件属性映射统计
1265
+
1266
+ | 映射类型 | 数量 | 占比 |
1267
+ |---------|------|------|
1268
+ | 直接映射 | 10 | ~40% |
1269
+ | 需类型转换 | 8 | ~32% |
1270
+ | 需组合实现 | 5 | ~20% |
1271
+ | 无直接对应 | 2 | ~8% |
1272
+ | **总计** | **25** | **100%** |
1273
+
1274
+ ---
1275
+
1276
+ ### 1.8 滚动类组件
1277
+
1278
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
1279
+ |-------------|------|---------------|---------|------|
1280
+ | ScrollView | `android.widget.ScrollView` | `Scroll` | 直接映射 | 垂直滚动视图 |
1281
+ | HorizontalScrollView | `android.widget.HorizontalScrollView` | `Scroll` (scrollable: ScrollDirection.Horizontal) | 方向配置 | 水平滚动视图 |
1282
+ | NestedScrollView | `androidx.core.widget.NestedScrollView` | `Scroll` + 嵌套 | 配合 List/Grid | 支持嵌套滚动的滚动视图 |
1283
+
1284
+ ---
1285
+
1286
+ #### 1.8.1 ScrollView → Scroll 属性映射
1287
+
1288
+ **滚动方向属性**
1289
+
1290
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1291
+ |-------------|---------------|---------|---------|
1292
+ | `android:orientation="vertical"` | `.scrollable()` | enum → ScrollDirection | Android: `android:orientation="vertical"`<br/>HarmonyOS: `Scroll() { ... }.scrollable(ScrollDirection.Vertical)` |
1293
+ | `android:orientation="horizontal"` | `.scrollable()` | enum → ScrollDirection | Android: `android:orientation="horizontal"`<br/>HarmonyOS: `Scroll() { ... }.scrollable(ScrollDirection.Horizontal)` |
1294
+
1295
+ **滚动条属性**
1296
+
1297
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1298
+ |-------------|---------------|---------|---------|
1299
+ | `android:scrollbars="vertical"` | `.scrollBar()` | enum → BarState | Android: `android:scrollbars="vertical"`<br/>HarmonyOS: `Scroll() { ... }.scrollBar(BarState.On)` |
1300
+ | `android:scrollbars="horizontal"` | `.scrollBar()` | enum → BarState | Android: `android:scrollbars="horizontal"`<br/>HarmonyOS: `Scroll() { ... }.scrollBar(BarState.On)` |
1301
+ | `android:scrollbars="none"` | `.scrollBar()` | enum → BarState | Android: `android:scrollbars="none"`<br/>HarmonyOS: `Scroll() { ... }.scrollBar(BarState.Off)` |
1302
+ | 无直接对应 | `.scrollBarColor()` | 无 → Color | Android: 无<br/>HarmonyOS: `Scroll() { ... }.scrollBarColor(Color.Gray)` |
1303
+ | 无直接对应 | `.scrollBarWidth()` | 无 → number | Android: 无<br/>HarmonyOS: `Scroll() { ... }.scrollBarWidth(30)` |
1304
+
1305
+ **滚动条样式映射**
1306
+
1307
+ | Android scrollbarStyle | HarmonyOS BarState | 说明 |
1308
+ |---------------------|-------------------|------|
1309
+ | `insideOverlay` | `BarState.Auto` | 滚动条在内容内,不占用空间 |
1310
+ | `insideInset` | `BarState.On` | 滚动条在内容内,占用空间 |
1311
+ | `outsideOverlay` | `BarState.Auto` | 滚动条在内容外,不占用空间 |
1312
+ | `outsideInset` | `BarState.On` | 滚动条在内容外,占用空间 |
1313
+
1314
+ **边缘效果属性**
1315
+
1316
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1317
+ |-------------|---------------|---------|---------|
1318
+ | `android:overScrollMode="always"` | `.edgeEffect()` | enum → EdgeEffect | Android: `android:overScrollMode="always"`<br/>Harmony HarmonyOS: `Scroll() { ... }.edgeEffect(EdgeEffect.Spring)` |
1319
+ | `android:overScrollMode="ifContentScrolls"` | `.edgeEffect()` | enum → EdgeEffect | Android: `android:overScrollMode="ifContentScrolls"`<br/>HarmonyOS: `Scroll() { ... }.edgeEffect(EdgeEffect.Spring)` |
1320
+ | `android:overScrollMode="never"` | `.edgeEffect()` | enum → EdgeEffect | Android: `android:overScrollMode="never"`<br/>HarmonyOS: `Scroll() { ... }.edgeEffect(EdgeEffect.None)` |
1321
+ | `android:overScrollHeader` | 无直接对应 | 需自定义实现 | 使用边缘效果 API |
1322
+
1323
+ **EdgeEffect 枚举值映射**
1324
+
1325
+ | Android overScrollMode | HarmonyOS EdgeEffect | 说明 |
1326
+ |---------------------|-------------------|------|
1327
+ | `always` | `EdgeEffect.Spring` | 始终显示弹性效果 |
1328
+ | `ifContentScrolls` | `EdgeEffect.Spring` | 内容可滚动时显示效果 |
1329
+ | `never` | `EdgeEffect.None` | 不显示边缘效果 |
1330
+
1331
+ **嵌套滚动属性**
1332
+
1333
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1334
+ |-------------|---------------|---------|---------|
1335
+ | `android:nestedScrollingEnabled="true"` | `.nestedScroll()` | boolean → NestedScrollOptions | Android: `android:nestedScrollingEnabled="true"`<br/>HarmonyOS: `Scroll() { ... }.nestedScroll({ scrollForward: NestedScrollMode.PARENT_FIRST, scrollBackward: NestedScrollMode.SELF_FIRST })` |
1336
+
1337
+ **NestedScrollMode 枚举值映射**
1338
+
1339
+ | Android 嵌套行为 | HarmonyOS NestedScrollMode | 说明 |
1340
+ |---------------------|-------------------------|------|
1341
+ | 自身先滚动 | `NestedScrollMode.SELF_FIRST` | 自身先滚动,再滚动父容器 |
1342
+ | 父容器先滚动 | `NestedScrollMode.PARENT_FIRST` | 父容器先滚动,再滚动自身 |
1343
+ | 仅自身滚动 | `NestedScrollMode.SELF_ONLY` | 只滚动自身,不传递给父容器 |
1344
+ | 并行滚动 | `NestedScrollMode.PARALLEL` | 自身和父容器同时滚动 |
1345
+ | 自动选择 | `NestedScrollMode.AUTO` | 系统自动选择滚动模式 |
1346
+
1347
+ **滚动填充属性**
1348
+
1349
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1350
+ |-------------|---------------|---------|---------|
1351
+ | `android:fillViewport` | 无直接对应 | 需自定义实现 | 使用尺寸约束 |
1352
+
1353
+ **滚动事件属性**
1354
+
1355
+ | Android 监听器 | HarmonyOS 属性 | 类型转换 | 代码示例 |
1356
+ |-------------|---------------|---------|---------|
1357
+ | `OnScrollListener.onScrollChanged()` | `.onScroll()` | 监听器 → 回调函数 | Android: `setOnScrollChangeListener(...)`<br/>HarmonyOS: `Scroll() { ... }.onScroll((xOffset: number, yOffset: number) => { ... })` |
1358
+ | `OnScrollListener.onScrollStateChanged()` | `.onScrollStart()` / `.onScrollEnd()` | 监听器 → 回调函数 | Android: `setOnScrollChangeListener(...)`<br/>HarmonyOS: `Scroll() { ... }.onScrollStart(() => { ... }).onScrollEnd(() => { ... })` |
1359
+ | 无直接对应 | `.onScrollEdge()` | 无 → 回调函数 | Android: 无<br/>HarmonyOS: `Scroll() { ... }.onScrollEdge((side: Edge) => { ... })` |
1360
+
1361
+ **滚动控制方法映射**
1362
+
1363
+ | Android 方法 | HarmonyOS 方法 | 类型转换 | 代码示例 |
1364
+ |-------------|---------------|---------|---------|
1365
+ | `scrollTo(int x, int y)` | `scroller.scrollTo()` | (int, int) → ({ xOffset, yOffset, animation }) | Android: `scrollView.scrollTo(100, 200)`<br/>HarmonyOS: `this.scroller.scrollTo({ xOffset: 100, yOffset: 200 })` |
1366
+ | `scrollBy(int dx, int dy)` | `scroller.scrollBy()` | (int, int) → (int, int) | Android: `scrollView.scrollBy(10, 20)`<br/>HarmonyOS: `this.scroller.scrollBy(10, 20)` |
1367
+ | `smoothScrollTo(int x, int y)` | `scroller.scrollTo()` | (int, int) → ({ xOffset, yOffset, animation }) | Android: `scrollView.smoothScrollTo(100, 200)`<br/>HarmonyOS: `this.scroller.scrollTo({ xOffset: 100, yOffset: 200, animation: { duration: 300 } })` |
1368
+ | `smoothScrollBy(int dx, int dy)` | `scroller.scrollBy()` | (int, int) → (int, int) | Android: `scrollView.smoothScrollBy(10, 20)`<br/>HarmonyOS: `this.scroller.scrollBy(10, 20)` |
1369
+ | `fullScroll(int direction)` | `scroller.scrollEdge()` | FOCUS_DOWN/UP → Edge | Android: `scrollView.fullScroll(FOCUS_DOWN)`<br/>HarmonyOS: `this.scroller.scrollEdge(Edge.Bottom)` |
1370
+ | `pageScroll(int direction)` | 无直接对应 | 需自定义实现 | 使用 `scroller.scrollPage()` |
1371
+ | `arrowScroll(int direction)` | 无直接对应 | 需自定义实现 | 使用 `scroller.scrollBy()` |
1372
+
1373
+ **滚动状态查询方法映射**
1374
+
1375
+ | Android 方法 | HarmonyOS 方法 | 类型转换 | 代码示例 |
1376
+ |-------------|---------------|---------|---------|
1377
+ | `getScrollX()` | `scroller.current()().xOffset` | void → number | Android: `scrollView.getScrollX()`<br/>HarmonyOS: `this.scroller.currentOffset().xOffset` |
1378
+ | `getScrollY()` | `scroller.currentOffset().yOffset` | void → number | Android: `scrollView.getScrollY()`<br/>HarmonyOS: `this.scroller.currentOffset().yOffset` |
1379
+ | `canScrollVertically()` | 无直接对应 | 需自定义实现 | 使用内容尺寸计算 |
1380
+ | `canScrollHorizontally()` | 无直接对应 | 需自定义实现 | 使用内容尺寸计算 |
1381
+
1382
+ **滚动动画属性**
1383
+
1384
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1385
+ |-------------|---------------|---------|---------|
1386
+ | 无直接对应 | `animation` | 无 → ScrollAnimateOptions | Android: 使用 ObjectAnimator<br/>HarmonyOS: `this.scroller.scrollTo({ xOffset: 100, yOffset: 200, animation: { duration: 500, curve: Curve.EaseInOut } })` |
1387
+
1388
+ ---
1389
+
1390
+ #### 1.8.2 HorizontalScrollView → Scroll 属性映射
1391
+
1392
+ **水平滚动特有属性**
1393
+
1394
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1395
+ |-------------|---------------|---------|---------|
1396
+ | `android:orientation` | `.scrollable()` | enum → ScrollDirection | Android: `android:orientation="horizontal"`<br/>HarmonyOS: `Scroll() { ... }.scrollable(ScrollDirection.Horizontal)` |
1397
+
1398
+ **其他属性**:与 ScrollView 相同,参考 1.8.1 ScrollView → Scroll 属性映射。
1399
+
1400
+ ---
1401
+
1402
+ #### 1.8.3 NestedScrollView → Scroll 属性映射
1403
+
1404
+ **嵌套滚动特有属性**
1405
+
1406
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1407
+ |-------------|---------------|---------|---------|
1408
+ | `android:nestedScrollingEnabled="true"` | `.nestedScroll()` | boolean → NestedScrollOptions | Android: `android:nestedScrollingEnabled="true"`<br/>HarmonyOS: `Scroll() { ... }.nestedScroll({ scrollForward: NestedScrollMode.PARENT_FIRST, scrollBackward: NestedScrollMode.SELF_FIRST })` |
1409
+
1410
+ **其他属性**:与 ScrollView 相同,参考 1.8.1 ScrollView → Scroll 属性映射。
1411
+
1412
+ ---
1413
+
1414
+ #### 1.8.4 Scroll 组件高级属性
1415
+
1416
+ **滚动交互属性**
1417
+
1418
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1419
+ |-------------|---------------|---------|---------|
1420
+ | 无直接对应 | `.enableScrollInteraction()` | 无 → boolean | Android: 无<br/>HarmonyOS: `Scroll() { ... }.enableScrollInteraction(false)` |
1421
+
1422
+ **滚动边缘枚举**
1423
+
1424
+ | HarmonyOS Edge | 说明 |
1425
+ |-----------------|------|
1426
+ | `Top` | 顶部边缘 |
1427
+ | `Bottom` | 底部边缘 |
1428
+ | `Start` | 起始边缘(RTL/LTR 感知) |
1429
+ | `End` | 结束边缘(RTL/LTR 感知) |
1430
+
1431
+ ---
1432
+
1433
+ #### 1.8.5 滚动组件属性映射统计
1434
+
1435
+ | 映射类型 | 数量 | 占比 |
1436
+ |---------|------|------|
1437
+ | 直接映射 | 15 | ~45% |
1438
+ | 需类型转换 | 10 | ~30% |
1439
+ | 需组合实现 | 5 | ~15% |
1440
+ | 无直接对应 | 3 | ~10% |
1441
+ | **总计** | **33** | **100%** |
1442
+
1443
+ ---
1444
+
1445
+ ## 二、布局容器组件映射
1446
+
1447
+ ### 2.1 线性布局
1448
+
1449
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
1450
+ |-------------|------|---------------|---------|------|
1451
+ | LinearLayout | `android.widget.LinearLayout` | `Column` / `Row` | 垂直用 Column,水平用 Row | 线性布局 |
1452
+ | TableRow | `android.widget.TableRow` | `Row` | 在 Grid 中使用 | 表格行(水平线性) |
1453
+
1454
+ ---
1455
+
1456
+ #### 2.1.1 LinearLayout → Column/Row 属性映射
1457
+
1458
+ **方向属性**
1459
+
1460
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1461
+ |-------------|---------------|---------|---------|
1462
+ | `android:orientation` | 无直接对应 | enum → 组件选择 | Android: `android:orientation="vertical"`<br/>HarmonyOS: 使用 `Column` 组件<br/>Android: `android:orientation="horizontal"`<br/>HarmonyOS: 使用 `Row` 组件 |
1463
+
1464
+ **内容对齐属性**
1465
+
1466
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1467
+ |-------------|---------------|---------|---------|
1468
+ | `android:gravity` | `.justifyContent()` / `.alignItems()` | flags → FlexAlign | Android: `android:gravity="center"`<br/>HarmonyOS: `Column().justifyContent(FlexAlign.Center)`<br/>Android: `android:gravity="center_horizontal"`<br/>HarmonyOS: `Row().alignItems(HorizontalAlign.Center)`<br/>Android: `android:gravity="center_vertical"`<br/>HarmonyOS: `Column().justifyContent(FlexAlign.Center)`<br/>Android: `android:gravity="left"`<br/>HarmonyOS: `Row().alignItems(HorizontalAlign.Start)`<br/>Android: `android:gravity="right"`<br/>HarmonyOS: `Row().alignItems(HorizontalAlign.End)`<br/>Android: `android:gravity="start"`<br/>HarmonyOS: `Row().alignItems(HorizontalAlign.Start)`<br/>Android: `android:gravity="end"`<br/>HarmonyOS: `Row().alignItems(HorizontalAlign.End)` |
1469
+
1470
+ **权重分配属性**
1471
+
1472
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1473
+ |-------------|---------------|---------|---------|
1474
+ | `android:weightSum` | 无直接对应 | float → 自动处理 | Android: `android:weightSum="1.0"`<br/>HarmonyOS: 自动处理,使用 `.layoutWeight()` |
1475
+
1476
+ **基线对齐属性**
1477
+
1478
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1479
+ |-------------|---------------|---------|---------|
1480
+ | `android:baselineAligned` | 无直接对应 | boolean → 需自定义实现 | Android: `android:baselineAligned="true"`<br/>HarmonyOS: 需自定义实现 |
1481
+
1482
+ **测量模式属性**
1483
+
1484
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1485
+ |-------------|---------------|---------|---------|
1486
+ | `android:measureWithLargestChild` | 无直接对应 | boolean → 需自定义实现 | Android: `android:measureWithLargestChild="true"`<br/>HarmonyOS: 需自定义实现 |
1487
+
1488
+ **分隔线属性**
1489
+
1490
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1491
+ |-------------|---------------|---------|---------|
1492
+ | `android:divider` | 无直接对应 | drawable → Divider 组件 | Android: `android:divider="@drawable/divider"`<br/>HarmonyOS: 在子组件间插入 `Divider()` 组件 |
1493
+ | `android:showDividers` | 无直接对应 | flags → 手动插入 | Android: `android:showDividers="middle"`<br/>HarmonyOS: 需手动插入 Divider 组件 |
1494
+ | `android:dividerPadding` | 无直接对应 | dimension → Divider padding | Android: `android:dividerPadding="8dp"`<br/>HarmonyOS: `Divider().padding(8)` |
1495
+
1496
+ ---
1497
+
1498
+ #### 2.1.2 LinearLayout 子组件布局属性映射
1499
+
1500
+ **对齐属性**
1501
+
1502
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1503
+ |-------------|---------------|---|---------|
1504
+ | `android:layout_gravity` | `.align()` | flags → Alignment | Android: `android:layout_gravity="center"`<br/>HarmonyOS: `.align(Alignment.Center)`<br/>Android: `android:layout_gravity="top"`<br/>HarmonyOS: `.align(Alignment.Top)`<br/>Android: `android:layout_gravity="bottom"`<br/>HarmonyOS: `.align(Alignment.Bottom)`<br/>Android: `android:layout_gravity="left"`<br/>HarmonyOS: `.align(Alignment.Start)`<br/>Android: `android:layout_gravity="right"`<br/>HarmonyOS: `.align(Alignment.End)`<br/>Android: `android:layout_gravity="center_horizontal"`<br/>HarmonyOS: `.align(Alignment.Center)`<br/>Android: `android:layout_gravity="start"`<br/>HarmonyOS: `.align(Alignment.Start)`<br/>Android: `android:layout_gravity="end"`<br/>HarmonyOS: `.align(Alignment.End)` |
1505
+
1506
+ **权重属性**
1507
+
1508
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1509
+ |-------------|---------------|---------|---------|
1510
+ | `android:layout_weight` | `.layoutWeight()` | float → number | Android: `android:layout_weight="1"`<br/>HarmonyOS: `.layoutWeight(1)` |
1511
+
1512
+ ---
1513
+
1514
+ #### 2.1.3 LinearLayout 程序化方法映射属性
1515
+
1516
+ | Android 方法 | HarmonyOS 属性 | 类型转换 | 代码示例 |
1517
+ |-------------|---------------|---------|---------|
1518
+ | `setOrientation(int)` | 无直接对应 | int → 组件选择 | Android: `linearLayout.setOrientation(LinearLayout.VERTICAL)`<br/>HarmonyOS: 使用 `Column` 组件 |
1519
+ | `getOrientation()` | 无直接对应 | void → 组件判断 | Android: `int orientation = linearLayout.getOrientation()`<br/>HarmonyOS: 根据组件类型判断 |
1520
+ | `setGravity(int)` | `.justifyContent()` / `.alignItems()` | int → FlexAlign | Android: `linearLayout.setGravity(Gravity.CENTER)`<br/>HarmonyOS: `Column().justifyContent(FlexAlign.Center)` |
1521
+ | `setWeightSum(float)` | 无直接对应 | float → 自动处理 | Android: `linearLayout.setWeightSum(1.0f)`<br/>HarmonyOS: 自动处理 |
1522
+ | `setBaselineAligned(boolean)` | 无直接对应 | boolean → 需自定义实现 | Android: `linearLayout.setBaselineAligned(true)`<br/>HarmonyOS: 需自定义实现 |
1523
+ | `setMeasureWithLargestChild(boolean)` | 无直接对应 | boolean → 需自定义实现 | Android: `linearLayout.setMeasureWithLargestChild(true)`<br/>HarmonyOS: 需自定义实现 |
1524
+ | `setDividerDrawable()` | 无直接对应 | Drawable → Divider 组件 | Android: `linearLayout.setDividerDrawable(divider)`<br/>HarmonyOS: 使用 `Divider()` 组件 |
1525
+ | `setShowDividers(int)` | 无直接对应 | int → 手动插入 | Android: `linearLayout.setShowDividers(SHOW_DIVIDER_MIDDLE)`<br/>HarmonyOS: 需手动插入 Divider 组件 |
1526
+ | `setDividerPadding(int)` | 无直接对应 | int → Divider padding | Android: `linearLayout.setDividerPadding(8)`<br/>HarmonyOS: `Divider().padding(8)` |
1527
+
1528
+ ---
1529
+
1530
+ #### 2.1.4 LinearLayout 属性映射统计
1531
+
1532
+ | 映射类型 | 数量 | 占比 |
1533
+ |---------|------|------|
1534
+ | 直接映射 | 6 | ~26% |
1535
+ | 需类型转换 | 4 | ~17% |
1536
+ | 需组合实现 | 8 | ~35% |
1537
+ | 无直接对应 | 5 | ~22% |
1538
+ | **总计** | **23** | **100%** |
1539
+
1540
+ ---
1541
+
1542
+ ### 2.2 相对布局
1543
+
1544
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
1545
+ |-------------|------|---------------|---------|------|
1546
+ | RelativeLayout | `android.widget.RelativeLayout` | `RelativeContainer` | 直接映射 | 相对布局 |
1547
+ | PercentRelativeLayout | `androidx.percentlayout.widget.PercentRelativeLayout` | `RelativeContainer` + 约束尺寸 | 已废弃 | 百分比相对布局 |
1548
+
1549
+ ---
1550
+
1551
+ #### 2.2.1 RelativeLayout → RelativeContainer 属性映射
1552
+
1553
+ **容器级别属性**
1554
+
1555
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1556
+ |-------------|---------------|---------|---------|
1557
+ | `android:gravity` | 无直接对应 | flags → 需自定义实现 | Android: `android:gravity="center"`<br/>HarmonyOS: 需自定义实现 |
1558
+
1559
+ **子组件相对父容器定位属性**
1560
+
1561
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1562
+ |-------------|---------------|---------|---------|
1563
+ | `android:layout_alignParentTop` | `.alignRules()` | boolean → alignRules | Android: `android:layout_alignParentTop="true"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: VerticalAlign.Top })` |
1564
+ | `android:layout_alignParentBottom` | `.alignRules()` | boolean → alignRules | Android: `android:layout_alignParentBottom="true"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: VerticalAlign.Bottom })` |
1565
+ | `android:layout_alignParentLeft` | `.alignRules()` | boolean → alignRules | Android: `android:layout_alignParentLeft="true"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: HorizontalAlign.Start })` |
1566
+ | `android:layout_alignParentRight` | `.alignRules()` | boolean → alignRules | Android: `android:layout_alignParentRight="true"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: HorizontalAlign.End })` |
1567
+ | `android:layout_alignParentStart` | `.alignRules()` | boolean → alignRules | Android: `android:layout_alignParentStart="true"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: HorizontalAlign.Start })` |
1568
+ | `android:layout_alignParentEnd` | `.alignRules()` | boolean → alignRules | Android: `android:layout_alignParentEnd="true"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: HorizontalAlign.End })` |
1569
+ | `android:layout_centerHorizontal` | `.alignRules()` | boolean → alignRules | Android: `android:layout_centerHorizontal="true"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: HorizontalAlign.Center })` |
1570
+ | `android:layout_centerVertical` | `.alignRules()` | boolean → alignRules | Android: `android:layout_centerVertical="true"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: VerticalAlign.Center })` |
1571
+ | `android:layout_centerInParent` | `.alignRules()` | boolean → alignRules | Android: `android:layout_centerInParent="true"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: Alignment.Center })` |
1572
+
1573
+ **子组件相对兄弟组件定位属性**
1574
+
1575
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1576
+ |-------------|---------------|---------|---------|
1577
+ | `android:layout_above` | `.alignRules()` | reference → alignRules | Android: `android:layout_above="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: VerticalAlign.Top })` |
1578
+ | `android:layout_below` | `.alignRules()` | reference → alignRules | Android: `android:layout_below="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: VerticalAlign.Bottom })` |
1579
+ | `android:layout_toLeftOf` | `.alignRules()` | reference → alignRules | Android: `android:layout_toLeftOf="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: HorizontalAlign.Start })` |
1580
+ | `android:layout_toRightOf` | `.alignRules()` | reference → alignRules | Android: `android:layout_toRightOf="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: HorizontalAlign.End })` |
1581
+ | `android:layout_toStartOf` | `.alignRules()` | reference → alignRules | Android: `android:layout_toStartOf="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: HorizontalAlign.Start })` |
1582
+ | `android:layout_toEndOf` | `.alignRules()` | reference → alignRules | Android: `android:layout_toEndOf="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: HorizontalAlign.End })` |
1583
+
1584
+ **子组件边缘对齐属性**
1585
+
1586
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1587
+ |-------------|---------------|---------|---------|
1588
+ | `android:layout_alignTop` | `.alignRules()` | reference → alignRules | Android: `android:layout_alignTop="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: VerticalAlign.Top })` |
1589
+ | `android:layout_alignBottom` | `.alignRules()` | reference → alignRules | Android: `android:layout_alignBottom="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: VerticalAlign.Bottom })` |
1590
+ | `android:layout_alignLeft` | `.alignRules()` | reference → alignRules | Android: `android:layout_alignLeft="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: HorizontalAlign.Start })` |
1591
+ | `android:layout_alignRight` | `.alignRules()` | reference → alignRules | Android: `android:layout_alignRight="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: HorizontalAlign.End })` |
1592
+ | `android:layout_alignStart` | `.alignRules()` | reference → alignRules | Android: `android:layout_alignStart="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: HorizontalAlign.Start })` |
1593
+ | `android:layout_alignEnd` | `.alignRules()` | reference → alignRules | Android: `android:layout_alignEnd="@id/sibling"`<br/>HarmonyOS:: `.alignRules({ anchor: 'sibling', align: HorizontalAlign.End })` |
1594
+ | `android:layout_alignBaseline` | `.alignRules()` | reference → alignRules | Android: `android:layout_alignBaseline="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: VerticalAlign.Center })` |
1595
+
1596
+ ---
1597
+
1598
+ #### 2.2.2 RelativeLayout 属性映射统计
1599
+
1600
+ | 映射类型 | 数量 | 占比 |
1601
+ |---------|------|------|
1602
+ | 直接映射 | 0 | ~0% |
1603
+ | 需类型转换 | 0 | ~0% |
1604
+ | 需组合实现 | 17 | ~100% |
1605
+ | 无直接对应 | 0 | ~0% |
1606
+ | **总计** | **17** | **100%** |
1607
+
1608
+ ---
1609
+
1610
+ ### 2.3 帧布局
1611
+
1612
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
1613
+ |-------------|------|---------------|---------|------|
1614
+ | FrameLayout | `android.widget.FrameLayout` | `Stack` | 直接映射 | 帧布局 |
1615
+ | DialerFilter | `android.widget.DialerFilter` | 自定义组合 | 需业务实现 | 拨号过滤器 |
1616
+ | TwoLineListItem | `android.widget.TwoLineListItem` | `Column` + 2个 `Text` | 已废弃 | 双行列表项 |
1617
+
1618
+ ---
1619
+
1620
+ #### 2.3.1 FrameLayout → Stack 属性映射
1621
+
1622
+ **容器级别属性**
1623
+
1624
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1625
+ |-------------|---------------|---------|---------|
1626
+ | `android:foreground` | 无直接对应 | drawable → 顶层组件 | Android: `android:foreground="@drawable/overlay"`<br/>HarmonyOS: 在 Stack 顶层添加 Image/Color 组件 |
1627
+ | `android:foregroundGravity` | `.alignContent()` | flags → Alignment | Android: `android:foregroundGravity="center"`<br/>HarmonyOS: `Stack({ alignContent: Alignment.Center })` |
1628
+ | `android:measureAllChildren` | 无直接对应 | boolean → 需自定义实现 | Android: `android:measureAllChildren="true"`<br/>HarmonyOS: 需自定义实现 |
1629
+
1630
+ **子组件布局属性**
1631
+
1632
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1633
+ |-------------|---------------|---------|---------|
1634
+ | `android:layout_gravity` | `.align()` | flags → Alignment | Android: `android:layout_gravity="center"`<br/>HarmonyOS: `.align(Alignment.Center)`<br/>Android: `android:layout_gravity="top"`<br/>HarmonyOS: `.align(Alignment.Top)`<br/>Android: `android:layout_gravity="bottom"`<br/>HarmonyOS: `.align(Alignment.Bottom)`<br/>Android: `android:layout_gravity="left"`<br/>HarmonyOS: `.align(Alignment.Start)`<br/>Android: `android:layout_gravity="right"`<br/>HarmonyOS: `.align(Alignment.End)`<br/>Android: `android:layout_gravity="center_horizontal"`<br/>HarmonyOS: `.align(Alignment.Center)`<br/>Android: `android:layout_gravity="center_vertical"`<br/>HarmonyOS: `.align(Alignment.Center)` |
1635
+
1636
+ ---
1637
+
1638
+ #### 2.3.2 FrameLayout 属性映射统计
1639
+
1640
+ | 映射类型 | 数量 | 占比 |
1641
+ |---------|------|------|
1642
+ | 直接映射 | 0 | ~0% |
1643
+ | 需类型转换 | 1 | ~6% |
1644
+ | 需组合实现 | 14 | ~88% |
1645
+ | 无直接对应 | 1 | ~6% |
1646
+ | **总计** | **16** | **100%** |
1647
+
1648
+ ---
1649
+
1650
+ ### 2.4 网格与表格布局
1651
+
1652
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
1653
+ |-------------|------|---------------|---------|------|
1654
+ | GridLayout | `android.widget.GridLayout` | `GridRow` + `GridCol` | 栅格系统 | 网格布局 |
1655
+ | TableLayout | `android.widget.TableLayout` | `Grid` | 自定义表格结构 | 表格布局 |
1656
+ | GridView | `android.widget.GridView` | `Grid` + `LazyForEach` | 高性能网格 | 网格视图(已废弃) |
1657
+
1658
+ ---
1659
+
1660
+ #### 2.4.1 GridLayout → GridRow/GridCol 属性映射
1661
+
1662
+ **栅格结构属性**
1663
+
1664
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1665
+ |-------------|---------------|---------|---------|
1666
+ | `android:columnCount` | `columnsTemplate` | int → template string | Android: `android:columnCount="3"`<br/>HarmonyOS: `GridRow({ columnsTemplate: '1fr 1fr 1fr' })` |
1667
+ | `android:rowCount` | 无直接对应 | int → 自动计算 | Android: `android:rowCount="2"`<br/>HarmonyOS: 自动根据 GridRow 数量计算 |
1668
+ | `android:orientation` | 无直接对应 | enum → 布局方向 | Android: `android:orientation="horizontal"`<br/>HarmonyOS: 使用`GridRow/GridCol` 嵌套结构 |
1669
+ | `android:useDefaultMargins` | 无直接对应 | boolean → 需自定义实现 | Android: `android:useDefaultMargins="true"`<br/>HarmonyOS: 需自定义实现 |
1670
+ | `android:alignmentMode` | 无直接对应 | enum → 需自定义实现 | Android: `android:alignmentMode="alignBounds"`<br/>HarmonyOS: 需自定义实现 |
1671
+ | `android:columnOrderPreserved` | 无直接对应 | boolean → 需自定义实现 | Android: `android:columnOrderPreserved="true"`<br/>HarmonyOS: 需自定义实现 |
1672
+ | `android:rowOrderPreserved` | 无直接对应 | boolean → 需自定义实现 | Android: `android:rowOrderPreserved="true"`<br/>HarmonyOS: 需自定义实现 |
1673
+
1674
+ **子组件单元格位置属性**
1675
+
1676
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1677
+ |-------------|---------------|---------|---------|
1678
+ | `android:layout_column` | 无直接对应 | int → GridCol 位置 | Android: `android:layout_column="1"`<br/>HarmonyOS: 通过`GridCol` 位置确定 |
1679
+ | `android:layout_row` | 无直接对应 | int → GridRow 位置 | Android: `android:layout_row="1"`<br/>HarmonyOS: 通过`GridRow` 位置确定 |
1680
+
1681
+ **子组件单元格跨度属性**
1682
+
1683
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1684
+ |-------------|---------------|---------|---------|
1685
+ | `android:layout_columnSpan` | `span` | int → number | Android: `android:layout_columnSpan="2"`<br/>HarmonyOS: `GridCol({ span: 2 })` |
1686
+ | `android:layout_rowSpan` | 无直接对应 | int → 需嵌套 GridRow | Android: `android:layout_rowSpan="2"`<br/>HarmonyOS: 需嵌套`GridRow` 实现 |
1687
+
1688
+ **子组件单元格权重属性**
1689
+
1690
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1691
+ |-------------|---------------|---------|---------|
1692
+ | `android:layout_columnWeight` | 无直接对应 | float → 百分比 | Android: `android:layout_columnWeight="1"`<br/>HarmonyOS: `GridCol().width('33.3%')` |
1693
+ | `android:layout_rowWeight` | 无直接对应 | float → 百分比 | Android: `android:layout_rowWeight="1"`<br/>HarmonyOS: `GridRow().height('50%')` |
1694
+
1695
+ **子组件单元格重力属性**
1696
+
1697
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1698
+ |-------------|---------------|---------|---------|
1699
+ | `android:layout_gravity` | `.align()` / `.justify()` | flags → Alignment | Android: `android:layout_gravity="center"`<br/>HarmonyOS: `.align(Alignment.Center)`<br/>Android: `android:layout_gravity="top"`<br/>HarmonyOS: `.align(Alignment.Top)`<br/>Android: `android:layout_gravity="bottom"`<br/>HarmonyOS: `.align(Alignment.Bottom)`<br/>Android: `android:layout_gravity="left"`<br/>HarmonyOS: `.align(Alignment.Start)`<br/>Android: `android:layout_gravity="right"`<br/>HarmonyOS: `.align(Alignment.End)`<br/>Android: `android:layout_gravity="center_horizontal"`<br/>HarmonyOS: `.align(Alignment.Center)`<br/>Android: `android:layout_gravity="center_vertical"`<br/>HarmonyOS: `.align(Alignment.Center)` |
1700
+
1701
+ ---
1702
+
1703
+ #### 2.4.2 GridLayout 属性映射统计
1704
+
1705
+ | 映射类型 | 数量 | 占比 |
1706
+ |---------|------|------|
1707
+ | 直接映射 | 2 | ~10% |
1708
+ | 需类型转换 | 4 | ~20% |
1709
+ | 需组合实现 | 10 | ~50% |
1710
+ | 无直接对应 | 4 | ~20% |
1711
+ | **总计** | **20** | **100%** |
1712
+
1713
+ ---
1714
+
1715
+ ### 2.5 约束布局 (ConstraintLayout)
1716
+
1717
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
1718
+ |-------------|------|---------------|---------|------|
1719
+ | ConstraintLayout | `androidx.constraintlayout.widget.ConstraintLayout` | `RelativeContainer` | 部分对应 | 约束布局 |
1720
+ | ConstraintSet | `androidx.constraintlayout.widget.ConstraintSet` | 自定义状态管理 | 动态配置 | 约束集合 |
1721
+ | Guideline | `androidx.constraintlayout.widget.Guideline` | 暂无直接对应 | 辅助 Absolute 定位 | 辅助线 |
1722
+ | Barrier | `androidx.constraintlayout.widget.Barrier` | 暂无直接对应 | 手动计算位置 | 屏障 |
1723
+ | Group | `androidx.constraintlayout.widget.Group` | 暂无直接对应 | 批量操作 | 组件组 |
1724
+ | Placeholder | `androidx.constraintlayout.widget.Placeholder` | 暂无直接对应 | 动态替换 | 占位符 |
1725
+ | Layer | `androidx.constraintlayout.helper.widget.Layer` | `Stack` | 组合其他容器 | 图层 |
1726
+ | Flow | `androidx.constraintlayout.helper.widget.Flow` | `Flex` | 流式布局 | 流式布局辅助 |
1727
+ | Grid | `androidx.constraintlayout.helper.widget.Grid` | `GridRow` + `GridCol` | 栅格系统 | 网格辅助 |
1728
+ | Carousel | `androidx.constraintlayout.helper.widget.Carousel` | `Swiper` | 轮播容器 | 轮播辅助 |
1729
+ | MotionLayout | `androidx.constraintlayout.motion.motion.widget.MotionLayout` | 动画 API 组合 | animateTo + transition | 动画布局 |
1730
+
1731
+ ---
1732
+
1733
+ #### 2.5.1 ConstraintLayout → RelativeContainer 属性映射
1734
+
1735
+ **容器级别属性**
1736
+
1737
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1738
+ |-------------|---------------|---------|---------|
1739
+ | `android:gravity` | 无直接对应 | flags → 需自定义实现 | Android: `android:gravity="center"`<br/>HarmonyOS: 需自定义实现 |
1740
+
1741
+ **子组件相对父容器定位属性**
1742
+
1743
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1744
+ |-------------|---------------|---------|---------|
1745
+ | `android:layout_constraintTop_toTopOf` | `.alignRules()` | reference → alignRules | Android: `android:layout_constraintTop_toTopOf="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: VerticalAlign.Top })` |
1746
+ | `android:layout_constraintBottom_toBottomOf` | `.alignRules()` | reference → alignRules | Android: `android:layout_constraintBottom_toBottomOf="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: VerticalAlign.Bottom })` |
1747
+ | `android:layout_constraintStart_toStartOf` | `.alignRules()` | reference → alignRules | Android: `android:layout_constraintStart_toStartOf="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: HorizontalAlign.Start })` |
1748
+ | `android:layout_constraintEnd_toEndOf` | `.alignRules()` | reference → alignRules | Android: `android:layout_constraintEnd_toEndOf="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: HorizontalAlign.End })` |
1749
+ | `android:layout_constraintLeft_toLeftOf` | `.alignRules()`()` | reference → alignRules | Android: `android:layout_constraintLeft_toLeftOf="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: HorizontalAlign.Start })` |
1750
+ | `android:layout_constraintRight_toRightOf` | `.alignRules()` | reference → alignRules | Android: `android:layout_constraintRight_toRightOf="@id/sibling"`<br/>HarmonyOS: `.alignRules({ anchor: 'sibling', align: HorizontalAlign.End })` |
1751
+
1752
+ **子组件相对父容器对齐属性**
1753
+
1754
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1755
+ |-------------|---------------|---------|---------|
1756
+ | `android:layout_constraintTop_toTopOf="parent"` | `.alignRules()` | parent → __container__ | Android: `android:layout_constraintTop_toTopOf="parent"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: VerticalAlign.Top })` |
1757
+ | `android:layout_constraintBottom_toBottomOf="parent"` | `.alignRules()` | parent → __container__ | Android: `android:layout_constraintBottom_toBottomOf="parent"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: VerticalAlign.Bottom })` |
1758
+ | `android:layout_constraintStart_toStartOf="parent"` | `.alignRules()` | parent → __container__ | Android: `android:layout_constraintStart_toStartOf="parent"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: HorizontalAlign.Start })` |
1759
+ | `android:layout_constraintEnd_toEndOf="parent"` | `.alignRules()` | parent → __container__ | Android: `android:layout_constraintEnd_toEndOf="parent"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: HorizontalAlign.End })` |
1760
+ | `android:layout_constraintLeft_toLeftOf="parent"` | `.alignRules()` | parent → __container__ | Android: `android:layout_constraintLeft_toLeftOf="parent"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: HorizontalAlign.Start })` |
1761
+ | `android:layout_constraintRight_toRightOf="parent"` | `.alignRules()` | parent → __container__ | Android: `android:layout_constraintRight_toRightOf="parent"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: HorizontalAlign.End })` |
1762
+
1763
+ **子组件居中属性**
1764
+
1765
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1766
+ |-------------|---------------|---------|---------|
1767
+ | `android:layout_constraintStart_toStartOf="parent"` + `android:layout_constraintEnd_toEndOf="parent"` | `.alignRules()` | 双约束 → 居中 | Android: 双边约束<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: HorizontalAlign.Center })` |
1768
+ | `android:layout_constraintTop_toTopOf="parent"` + `android:layout_constraintBottom_toBottomOf="parent"` | `.alignRules()` | 双约束 → 居中 | Android: 双边约束<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: VerticalAlign.Center })` |
1769
+ | `android:layout_centerInParent="true"` | `.alignRules()` | boolean → 居中 | Android: `android:layout_centerInParent="true"`<br/>HarmonyOS: `.alignRules({ anchor: '__container__', align: Alignment.Center })` |
1770
+
1771
+ **子组件尺寸约束属性**
1772
+
1773
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1774
+ |-------------|---------------|---------|---------|
1775
+ | `android:layout_constraintWidth_default` | 无直接对应 | enum → 需自定义实现 | Android: `android:layout_constraintWidth_default="spread"`<br/>HarmonyOS: 需自定义实现 |
1776
+ | `android:layout_constraintHeight_default` | 无直接对应 | enum → 需自定义实现 | Android: `android:layout_constraintHeight_default="spread"`<br/>HarmonyOS: 需自定义实现 |
1777
+ | `android:layout_constraintWidth_min` | `.constraintSize()` | dimension → minWidth | Android: `android:layout_constraintWidth_min="100dp"`<br/>HarmonyOS: `.constraintSize({ minWidth: 100 })` |
1778
+ | `android:layout_constraintHeight_min` | `.constraintSize()` | dimension → minHeight | Android: `android:layout_constraintHeight_min="100dp"`<br/>HarmonyOS: `.constraintSize({ minHeight: 100 })` |
1779
+ | `android:layout_constraintWidth_max` | `.constraintSize()` | dimension → maxWidth | Android: `android:layout_constraintWidth_max="200dp"`<br/>HarmonyOS: `.constraintSize({ maxWidth: 200 })` |
1780
+ | `android:layout_constraintHeight_max` | `.constraintSize()` | dimension → maxHeight | Android: `android:layout_constraintHeight_max="200dp"`<br/>HarmonyOS: `.constraintSize({ maxHeight: 200 })` |
1781
+ | `android:layout_constraintWidth_percent` | `.width()` | float → 百分比 | Android: `android:layout_constraintWidth_percent="0.5"`<br/>HarmonyOS: `.width('50%')` |
1782
+ | `android:layout_constraintHeight_percent` | `.height()` | float → 百分比 | Android: `android:layout_constraintHeight_percent="0.5"`<br/>HarmonyOS: `.height('50%')` |
1783
+ | `android:layout_constraintDimensionRatio` | 无直接对应 | string → 需自定义实现 | Android: `android:layout_constraintDimensionRatio="16:9"`<br/>HarmonyOS: 需自定义实现 |
1784
+
1785
+ **偏置属性**
1786
+
1787
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1788
+ |-------------|---------------|---------|---------|
1789
+ | `android:layout_constraintHorizontal_bias` | 无直接对应 | float → 需自定义实现 | Android: `android:layout_constraintHorizontal_bias="0.5"`<br/>HarmonyOS: 需自定义实现 |
1790
+ | `android:layout_constraintVertical_bias` | 无直接对应 | float → 需自定义实现 | Android: `android:layout_constraintVertical_bias="0.5"`<br/>HarmonyOS: 需自定义实现 |
1791
+
1792
+ **链式布局属性**
1793
+
1794
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1795
+ |-------------|---------------|---------|---------|
1796
+ | `android:layout_constraintHorizontal_chainStyle` | 无直接对应 | enum → 需自定义实现 | Android: `android:layout_constraintHorizontal_chainStyle="spread"`<br/>HarmonyOS: 需自定义实现 |
1797
+ | `android:layout_constraintVertical_chainStyle` | 无直接对应 | enum → 需自定义实现 | Android: `android:layout_constraintVertical_chainStyle="spread"`<br/>HarmonyOS: 需自定义实现 |
1798
+ | `android:layout_constraintHorizontal_weight` | `.layoutWeight()` | float → number | Android: `android:layout_constraintHorizontal_weight="1"`<br/>HarmonyOS: `.layoutWeight(1)` |
1799
+ | `android:layout_constraintVertical_weight` | `.layoutWeight()` | float → number | Android: `android:layout_constraintVertical_weight="1"`<br/>HarmonyOS: `.layoutWeight(1)` |
1800
+
1801
+ **圆形定位属性**
1802
+
1803
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1804
+ |-------------|---------------|---------|---------|
1805
+ | `android:layout_constraintCircle` | 无直接对应 | reference → 需自定义实现 | Android: `android:layout_constraintCircle="@id/center"`<br/>HarmonyOS: 需自定义实现 |
1806
+ | `android:layout_constraintCircleRadius` | 无直接对应 | dimension → 需自定义实现 | Android: `android:layout_constraintCircleRadius="100dp"`<br/>HarmonyOS: 需自定义实现 |
1807
+ | `android:layout_constraintCircleAngle` | 无直接对应 | float → 需自定义实现 | Android: `android:layout_constraintCircleAngle="45"`<br/>HarmonyOS: 需自定义实现 |
1808
+
1809
+ ---
1810
+
1811
+ #### 2.5.2 ConstraintLayout 辅助组件属性映射
1812
+
1813
+ **Guideline 属性**
1814
+
1815
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1816
+ |-------------|---------------|---------|---------|
1817
+ | `android:orientation` | 无直接对应 | enum → 需自定义实现 | Android: `android:orientation="horizontal"`<br/>HarmonyOS: 需自定义实现 |
1818
+ | `android:layout_constraintGuide_begin` | 无直接对应 | dimension → 需自定义实现 | Android: `android:layout_constraintGuide_begin="100dp"`<br/>HarmonyOS: 需自定义实现 |
1819
+ | `android:layout_constraintGuide_end` | 无直接对应 | dimension → 需自定义实现 | Android: `android:layout_constraintGuide_end="100dp"`<br/>HarmonyOS: 需自定义实现 |
1820
+ | `android:layout_constraintGuide_percent` | 无直接对应 | float → 需自定义实现 | Android: `android:layout_constraintGuide_percent="0.5"`<br/>HarmonyOS: 需自定义实现 |
1821
+
1822
+ **Barrier 属性**
1823
+
1824
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1825
+ |-------------|---------------|---------|---------|
1826
+ | `android:id` | `.id()` | reference → string | Android: `android:id="@+id/barrier"`<br/>HarmonyOS: `.id('barrier')` |
1827
+ | `app:barrierDirection` | 无直接对应 | enum → 需自定义实现 | Android: `app:barrierDirection="top"`<br/>HarmonyOS: 需自定义实现 |
1828
+ | `app:constraint_referenced_ids` | 无直接对应 | id list → 需自定义实现 | Android: `app:constraint_referenced_ids="@id/view1,@id/view2"`<br/>HarmonyOS: 需自定义实现 |
1829
+
1830
+ **Group 属性**
1831
+
1832
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1833
+ |-------------|---------------|---------|---------|
1834
+ | `android:id` | `.id()` | reference) → string | Android: `android:id="@+id/group"`<br/>HarmonyOS: `.id('group')` |
1835
+ | `app:constraint_referenced_ids` | 无直接对应 | id list → 需自定义实现 | Android: `app:constraint_referenced_ids="@id/view1,@id/view2"`<br/>HarmonyOS: 需自定义实现 |
1836
+ | `android:visibility` | `.visibility()` | enum → Visibility | Android: `android:visibility="gone"`<br/>HarmonyOS: `.visibility(Visibility.None)` |
1837
+ | `android:elevation` | `.shadow()` | dimension → shadow | Android: `android:elevation="8dp"`<br/>HarmonyOS: `.shadow({ radius: 8 })` |
1838
+
1839
+ **Placeholder 属性**
1840
+
1841
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1842
+ |-------------|---------------|---------|---------|
1843
+ | `android:id` | `.id()` | reference → string | Android: `android:id="@+id/placeholder"`<br/>HarmonyOS: `.id('placeholder')` |
1844
+ | `android:content` | 无直接对应 | reference → 需自定义实现 | Android: `android:content="@id/view"`<br/>HarmonyOS: 需自定义实现 |
1845
+ | `android:emptyVisibility` | `.visibility()` | enum → Visibility | Android: `android:emptyVisibility="gone"`<br/>HarmonyOS: `.visibility(Visibility.None)` |
1846
+
1847
+ **Layer 属性**
1848
+
1849
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1850
+ |-------------|---------------|---------|---------|
1851
+ | `android:id` | `.id()` | reference → string | Android: `android:id="@+id/layer"`<br/>HarmonyOS: `.id('layer')` |
1852
+ | `app:constraint_referenced_ids` | 无直接对应 | id list → 需自定义实现 | Android: `app:constraint_referenced_ids="@id/view1,@id/view2"`<br/>HarmonyOS: 需自定义实现 |
1853
+ | `android:rotation` | `.rotate()` | float → { angle: number } | Android: `android:rotation="45"`<br/>HarmonyOS: `.rotate({ angle: 45 })` |
1854
+ | `android:scaleX` | `.scale()` | float → { x: number } | Android: `android:scaleX="1.5"`<br/>HarmonyOS: `.scale({ x: 1.5 })` |
1855
+ | `android:scaleY` | `.scale()` | float → { y: number } | Android: `android:scaleY="1.5"`<br/>HarmonyOS: `.scale({ y: 1.5 })` |
1856
+ | `android:translationX` | `.translate()` | float → { x: number } | Android: `android:translationX="100"`<br/>HarmonyOS: `.translate({ x: 100 })` |
1857
+ | `android:translationY` | `.translate()` | float → { y: number } | Android: `android:translationY="100"`<br/>HarmonyOS: `.translate({ y: 100 })` |
1858
+
1859
+ **Flow 属性**
1860
+
1861
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1862
+ |-------------|---------------|---------|---------|
1863
+ | `android:id` | `.id()` | reference → string | Android: `android:id="@+id/flow"`<br/>HarmonyOS: `.id('flow')` |
1864
+ | `app:constraint_referenced_ids` | 无直接对应 | id list → 需自定义实现 | Android: `app:constraint_referenced_ids="@id/view1,@id/view2"`<br/>HarmonyOS: 需自定义实现 |
1865
+ | `app:flow_wrapMode` | 无直接对应 | enum → 需自定义实现 | Android: `app:flow_wrapMode="none"`<br/>HarmonyOS: 需自定义实现 |
1866
+ | `app:flow_horizontalStyle` | 无直接对应 | enum → 需自定义实现 | Android: `app:flow_horizontalStyle="spread"`<br/>HarmonyOS: 需自定义实现 |
1867
+ | `app:flow_verticalStyle` | 无直接对应 | enum → 需自定义实现 | Android: `app:flow_verticalStyle="spread"`<br/>HarmonyOS: 需自定义实现 |
1868
+ | `app`flow_horizontalGap` | 无直接对应 | dimension → 需自定义实现 | Android: `app:flow_horizontalGap="8dp"`<br/>HarmonyOS: 需自定义实现 |
1869
+ | `app:flow_verticalGap` | 无直接对应 | dimension → 需自定义实现 | Android: `app:flow_verticalGap="8dp"`<br/>HarmonyOS: 需自定义实现 |
1870
+ | `app:flow_maxElementsWrap` | 无直接对应 | int → 需自定义实现 | Android: `app:flow_maxElementsWrap="3"`<br/>HarmonyOS: 需自定义实现 |
1871
+ | `app:flow_firstHorizontalStyle` | 无直接对应 | enum → 需自定义实现 | Android: `app:flow_firstHorizontalStyle="spread"`<br/>HarmonyOS: 需自定义实现 |
1872
+ | `app:flow_firstVerticalStyle` | 无直接对应 | enum → 需自定义实现 | Android: `app:flow_firstVerticalStyle="spread"`<br/>HarmonyOS: 需自定义实现 |
1873
+ | `app:flow_lastHorizontalStyle` | 无直接对应 | enum → 需自定义实现 | Android: `app:flow_lastHorizontalStyle="spread"`<br/>HarmonyOS: 需自定义实现 |
1874
+ | `app:flow_lastVerticalStyle` | 无直接对应 | enum → 需自定义实现 | Android: `app:flow_lastVerticalStyle="spread"`<br/>HarmonyOS: 需自定义实现 |
1875
+
1876
+ **Grid 辅助组件属性**
1877
+
1878
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1879
+ |-------------|---------------|---------|---------|
1880
+ | `android:id` | `.id()` | reference → string | Android: `android:id="@+id/grid"`<br/>HarmonyOS: `.id('grid')` |
1881
+ | `app:constraint_referenced_ids` | 无直接对应 | id list → 需自定义实现 | Android: `app:constraint_referenced_ids="@id/view1,@id/view2"`<br/>HarmonyOS: 需自定义实现 |
1882
+ | `app:grid_columns` | 无直接对应 | int → 需自定义实现 | Android: `app:grid_columns="3"`<br/>HarmonyOS: 需自定义实现 |
1883
+ | `app:grid_rows` | 无直接对应 | int → 需自定义实现 | Android: `app:grid_rows="2"`<br/>HarmonyOS: 需自定义实现 |
1884
+ | `app:grid_columnWeights` | 无直接对应 | string → 需自定义实现 | Android: `app:grid_columnWeights="1,2,1"`<br/>HarmonyOS: 需自定义实现 |
1885
+ | `app:grid_rowWeights` | 无直接对应 | string → 需自定义实现 | Android: `app:grid_rowWeights="1,2"`<br/>HarmonyOS: 需自定义实现 |
1886
+ | `app:grid_horizontalGap` | 无直接对应 | dimension → 需自定义实现 | Android: `app:grid_horizontalGap="8dp"`<br/>HarmonyOS: 需自定义实现 |
1887
+ | `app:grid_verticalGap` | 无直接对应 | dimension → 需自定义实现 | Android: `app:grid_verticalGap="8dp"`<br/>HarmonyOS: 需自定义实现) |
1888
+ | `app:grid_useAsMeasurer` | 无直接对应 | boolean → 需自定义实现 | Android: `app:grid_useAsMeasurer="true"`<br/>HarmonyOS: 需自定义实现 |
1889
+
1890
+ **Carousel 辅助组件属性**
1891
+
1892
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1893
+ |-------------|---------------|---------|---------|
1894
+ | `android:id` | `.id()` | reference → string | Android: `android:id="@+id/carousel"`<br/>HarmonyOS: `.id('carousel')` |
1895
+ | `app:constraint_referenced_ids` | 无直接对应 | id list → 需自定义实现 | Android: `app:constraint_referenced_ids="@id/view1,@id/view2"`<br/>HarmonyOS: 需自定义实现 |
1896
+ | `app:carousel_forwardDirection` | 无直接对应 | enum → 需自定义实现 | Android: `app:carousel_forwardDirection="horizontal"`<br/>HarmonyOS: 需自定义实现 |
1897
+ | `app:carousel_infinite` | 无直接对应 | boolean → 需自定义实现 | Android: `app:carousel_infinite="true"`<br/>HarmonyOS: 需自定义实现 |
1898
+ | `app:carousel_previousState` | 无直接对应 | enum → 需自定义实现 | Android: `app:carousel_previousState="first"`<br/>HarmonyOS: 需自定义实现 |
1899
+ | `app:carousel_nextState` | 无直接对应 | enum) → 需自定义实现 | Android: `app:carousel_nextState="last"`<br/>HarmonyOS: 需自定义实现 |
1900
+
1901
+ **MotionLayout 属性**
1902
+
1903
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1904
+ |-------------|---------------|---------|---------|
1905
+ | `android:layoutDescription` | 无直接对应 | reference → 需自定义实现 | Android: `android:layoutDescription="@xml/motion_scene"`<br/>HarmonyOS: 需自定义实现 |
1906
+ | `app:showPaths` | 无直接对应 | boolean → 需自定义实现 | Android: `app:showPaths="true"`<br/>HarmonyOS: 需自定义实现 |
1907
+ | `app:progress` | 无直接对应 | float → 需自定义实现 | Android: `app:progress="0.5"`<br/>HarmonyOS: 需自定义实现 |
1908
+ | `app:applyMotionScene` | 无直接对应 | boolean → 需自定义实现 | Android: `app:applyMotionScene="true"`<br/>HarmonyOS: 需自定义实现 |
1909
+
1910
+ ---
1911
+
1912
+ #### 2.5.3 ConstraintLayout 属性映射统计
1913
+
1914
+ | 映射类型 | 数量 | 占比 |
1915
+ |---------|------|------|
1916
+ | 直接映射 | 5 | ~5% |
1917
+ | 需类型转换 | 15 | ~15% |
1918
+ | 需组合实现 | 80 | ~80% |
1919
+ | 无直接对应 | 0 | ~0% |
1920
+ | **总计** | **100** | **100%** |
1921
+
1922
+ ---
1923
+
1924
+ ### 2.6 弹性布局
1925
+
1926
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
1927
+ |-------------|------|---------------|---------|------|
1928
+ | FlexboxLayout | `com.google.android.flexbox.FlexboxLayout` | `Flex` | 直接映射 | 弹性盒子布局 |
1929
+
1930
+ ---
1931
+
1932
+ #### 2.6.1 FlexboxLayout → Flex 属性映射
1933
+
1934
+ **容器级别 Flex 属性**
1935
+
1936
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1937
+ |-------------|---------------|---------|---------|---------|
1938
+ | `app:flexDirection` | `.direction()` | enum → FlexDirection | Android: `app:flexDirection="row"`<br/>HarmonyOS: `Flex({ direction: FlexDirection.Row })` |
1939
+ | `app:flexDirection="column"` | `.direction()` | enum → FlexDirection | Android: `app:flexDirection="column"`<br/>HarmonyOS: `Flex({ direction: FlexDirection.Column })` |
1940
+ | `app:flexDirection="row_reverse"` | `.direction()` | enum → FlexDirection | Android: `app:flexDirection="row_reverse"`<br/>HarmonyOS: `Flex({ direction: FlexDirection.RowReverse })` |
1941
+ | `app:flexDirection="column_reverse"` | `.direction()` | enum → {direction: FlexDirection.ColumnReverse}` | Android: `app:flexDirection="column_reverse"`<br/>HarmonyOS: `Flex({ direction: FlexDirection.ColumnReverse })` |
1942
+
1943
+ **容器对齐属性**
1944
+
1945
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1946
+ |-------------|---------------|---------|---------|---------|
1947
+ | `app:justifyContent` | `.justifyContent()` | flags → FlexAlign | Android: `app:justifyContent="flex_start"`<br/>HarmonyOS: `Flex({ justifyContent: FlexAlign.Start })` |
1948
+ | `app:justifyContent="flex_end"` | `.justifyContent()` | flags → FlexAlign | Android: `app:justifyContent="flex_end"`<br/>HarmonyOS: `Flex({ justifyContent: FlexAlign.End })` |
1949
+ | `app:justifyContent="center"` | `.justifyContent()` | flags → FlexAlign | Android: `app:justifyContent="center"`<br/>HarmonyOS: `Flex({ justifyContent: FlexAlign.Center })` |
1950
+ | `app:justifyContent="space_between"` | `.justifyContent()` | flags → FlexAlign | Android: `app:justifyContent="space_between"`<br/>HarmonyOS: `Flex({ justifyContent: FlexAlign.SpaceBetween })` |
1951
+ | `app:justifyContent="space_around"` | `.justifyContent()` | flags → FlexAlign | Android: `app:justifyContent="space_around"`<br/>HarmonyOS: `Flex({ justifyContent: FlexAlign.SpaceAround })` |
1952
+ | `app:justifyContent="space_evenly"` | `.justifyContent()` | flags → FlexAlign | Android: `app:justifyContent="space_evenly"`<br/>HarmonyOS: `Flex({ justifyContent: FlexAlign.SpaceEvenly })` |
1953
+
1954
+ **子组件对齐属性**
1955
+
1956
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1957
+ |-------------|---------------|---------|---------|---------|---------|
1958
+ | `app:alignItems` | `.alignItems()` | enum → ItemAlign | Android: `app:alignItems="flex_start"`<br/>HarmonyOS: `Flex({ alignItems: ItemAlign.Start })` |
1959
+ | `app:alignItems="flex_end"` | `.alignItems()` | enum → ItemAlign | Android: `app:alignItems="flex_end"`<br/>HarmonyOS: `Flex({ alignItems: ItemAlign.End })` |
1960
+ | `app:alignItems="center"` | `.alignItems()` | flags → ItemAlign | Android: `app:alignItems="center"`<br/>HarmonyOS: `Flex({ alignItems: ItemAlign.Center })` |
1961
+ | `app:alignItems="baseline"` | `.alignItems()` | enum → ItemAlign | Android: `app:alignItems="baseline"`<br/>HarmonyOS: `Flex({ alignItems: ItemAlign.Baseline })` |
1962
+ | `app:alignItems="stretch"` | `.alignItems()` | flags → ItemAlign | Android: `app:alignItems="stretch"`<br/>HarmonyOS: `Flex({ alignItems: ItemAlign.Stretch })` |
1963
+
1964
+ **行内对齐属性**
1965
+
1966
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1967
+ |-------------|---------------|---------|---------|---------|---------|
1968
+ | `app:alignContent` | `.alignContent()` | flags → FlexAlign | Android: `app:alignContent="flex_start"`<br/>HarmonyOS: `Flex({ alignContent: FlexAlign.Start })` |
1969
+ | `app:alignContent="flex_end"` | `.alignContent()` | flags → FlexAlign | Android: `app:alignContent="flex_end"`<br/>HarmonyOS: `Flex({ alignContent: FlexAlign.End })` |
1970
+ | `app:alignContent="center"` | `.alignContent()` | flags → FlexAlign | Android: `app:alignContent="center"`<br/>HarmonyOS: `Flex({ alignContent: FlexAlign.Center })` |
1971
+ | `app:alignContent="space_between"` | `.alignContent()` | flags → FlexAlign | Android: `app:alignContent="space_between"`<br/>HarmonyOS: `Flex({ alignContent: FlexAlign.SpaceBetween })` |
1972
+ | `app:alignContent="space_around"` | `.alignContent()` | flags → FlexAlign | Android: `app:alignContent="space_around"`<br/>HarmonyOS: `Flex({ alignContent: FlexAlign.SpaceAround })` |
1973
+ | `app:alignContent="space_evenly"` | `.alignContent()` | flags → FlexAlign | Android: `app:alignContent="space_evenly"`<br/>HarmonyOS: `Flex({ alignContent: FlexAlign.SpaceEvenly })` |
1974
+
1975
+ **换行属性**
1976
+
1977
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1978
+ |-------------|---------------|---------|---------|---------|---------|
1979
+ | `app:flexWrap` | `.wrap()` | enum → FlexWrap | Android: `app:flexWrap="nowrap"`<br/>HarmonyOS: `Flex({ wrap: FlexWrap.NoWrap })` |
1980
+ | `app:flexWrap="wrap"` | `.wrap()` | enum → FlexWrap | Android: `app:flexWrap="wrap"`<br/>HarmonyOS: `Flex({ wrap: FlexWrap.Wrap })` |
1981
+ | `app:flexWrap="wrap_reverse"` | `.wrap()` | enum → FlexWrap | Android: `app:flexWrap="wrap_reverse"`<br/>HarmonyOS: `Flex({ wrap: FlexWrap.WrapReverse })` |
1982
+
1983
+ ---
1984
+
1985
+ #### 2.6.2 FlexboxLayout 子组件布局属性映射
1986
+
1987
+ **Flex Item 属性**
1988
+
1989
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1990
+ |-------------|---------------|---------|---------|---------|---------|
1991
+ | `app:layout_flexGrow` | `.flexGrow()` | float → number | Android: `app:layout_flexGrow="1"`<br/>HarmonyOS: `.flexGrow(1)` |
1992
+ | `app:layout_flexShrink` | `.flexShrink()` | float → number | Android: `app:layout_flexShrink="1"`<br/>HarmonyOS: `.flexShrink(1)` |
1993
+ | `app:layout_flexBasisPercent` | `.flexBasis()` | float → 百分比 | Android: `app:layout_flexBasisPercent="50%"`<br/>HarmonyOS: `.flexBasis('50%')` |
1994
+ | `app:layout_flexBasis` | dimension | 固定大小 | Android: `app:layout_flexBasis="100dp"`<br/>HarmonyOS: `.flexBasis(100)` |
1995
+
1996
+ **对齐属性**
1997
+
1998
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
1999
+ |-------------|---------------|---------|---------|---------|---------|---------|
2000
+ | `app:layout_alignSelf` | `.alignSelf()` | enum → ItemAlign | Android: `app:layout_alignSelf="auto"`<br/>HarmonyOS: `.alignSelf(ItemAlign.Auto)` |
2001
+ | `app:layout_alignSelf="flex_start"` | `.alignSelf()` | enum → ItemAlign | Android: `app:layout_alignSelf="flex_start"`<br/>HarmonyOS: `.alignSelf(ItemAlign.Start)` |
2002
+ | `app:layout_alignSelf="flex_end"` | `.alignSelf()` | enum → ItemAlign | Android: `app:layout_alignSelf="flex_end"`<br/>HarmonyOS: `.alignSelf(ItemAlign.End)` |
2003
+ | `app:layout_alignSelf="center"` | `.alignSelf()` | enum → ItemAlign | Android: `app:layout_alignSelf="center"`<br/>HarmonyOS: `.alignSelf(ItemAlign.Center)` |
2004
+ | `app:layout_alignSelf="baseline"` | `.alignSelf()` | enum → ItemAlign | Android: `app:layout_alignSelf="baseline"`<br/>HarmonyOS: `.alignSelf(ItemAlign.Baseline)` |
2005
+ | `app:layout_alignSelf="stretch"` | `.alignSelf()` | enum → ItemAlign | Android: `app:layout_alignSelf="stretch"`<br/>HarmonyOS: `.alignSelf(ItemAlign.Stretch)` |
2006
+
2007
+ **重力属性**
2008
+
2009
+ | Android XML | HarmonyOS 属性 | 类型转换 | 代码示例 |
2010
+ |-------------|---------------|---------|---------|---------|---------|---------|
2011
+ | `android:layout_gravity` | `.align()` / `.justify()` | flags → Alignment | Android: `android:layout_gravity="center"`<br/>HarmonyOS: `.align(Alignment.Center)`<br/>Android: `android:layout_gravity="center_horizontal"`<br/>HarmonyOS: `.alignItems(HorizontalAlign.Center)`<br/>Android: `android:layout_gravity="center_vertical"`<br/>HarmonyOS: `.justifyContent(FlexAlign.Center)`<br/>Android: `android:layout_gravity="left"`<br/>HarmonyOS: `.alignItems(VerticalAlign.Top)`<br/>Android: `android:layout_gravity="right"``<br/>HarmonyOS: `.alignItems(VerticalAlign.Bottom)`<br/>Android: `android:layout_gravity="center_horizontal"`<br/>HarmonyOS: `.alignItems(HorizontalAlign.Center)`<br/>Android: `android:layout_gravity="start"`<br/>HarmonyOS: `.alignItems(HorizontalAlign.Start)`<br/>Android: `android:layout_gravity="end"`<br/>HarmonyOS: `.alignItems(HorizontalAlign.End)`<br/>Android: `android:layout_gravity="center_vertical"`<br/>HarmonyOS: `.justifyContent(FlexAlign.Center)`<br/>Android: `android:layout_gravity="left"`<br/>HarmonyOS: `.alignItems(VerticalAlign.Top)`<br/>Android: `android:layout_gravity="right"`<br/>HarmonyOS: `.alignItems(VerticalAlign.Bottom)`<br/>Android: `android:layout_gravity="center_horizontal"`<br/>HarmonyOS: `.alignItems(HorizontalAlign.Center)`<br/>Android: `android:layout_gravity="start"`<br/>HarmonyOS: `.alignItems(HorizontalAlign.Start)`<br/>Android: `android:layout_gravity="end"`<br/>HarmonyOS: `.alignItems(VerticalAlign.Bottom)`<br/>Android: `android:layout_gravity="center_vertical"`<br/>HarmonyOS: `.align(Alignment.Center)`<br/>Android: `android:layout_gravity="left"`<br/>HarmonyOS: `.alignItems(VerticalAlign.Top)`<br/>Android: `android:layout_gravity="right"`<br/>HarmonyOS: `.alignItems(VerticalAlign.End)`<br/>Android: `android:layout_gravity="start"`<br/>HarmonyOS: `.alignItems(VerticalAlign.Start)`<br/>Android: `android:layout_gravity="end"`<br/>HarmonyOS: `.alignItems(VerticalAlign.End)`<br/>Android: `android:layout_gravity="center_vertical"`<br/>HarmonyOS: `.align(Alignment.Center)`<```
2012
+
2013
+ ---
2014
+
2015
+ #### 2.6.3 FlexboxLayout 程序化方法映射
2016
+
2017
+ | Android 方法 | HarmonyOS 属性 | 类型转换 | 代码示例 |
2018
+ |-------------|---------------|---------|---------|---------|---------|
2019
+ | `setFlexDirection(int)` | 无直接对应 | int → 组件选择 | Android: `flexboxLayout.setFlexDirection(LinearLayout.VERTICAL)`<br/>HarmonyOS: 使用 `Column` 或 `Row` 组件 |
2020
+ | `getFlexDirection()` | 无直接对应 | void → 组件判断 | Android: `int orientation = flexboxLayout.getFlexDirection()`<br/>HarmonyOS: 根据组件类型判断 |
2021
+ | `setGravity(int)` | `.justifyContent()` / `.alignItems()` | int → FlexAlign | Android: `flexboxLayout.setGravity(Gravity.CENTER)`<br/>HarmonyOS: `Flex().justifyContent(FlexAlign.Center).alignItems(HorizontalAlign.Center)` |
2022
+
2023
+ ---
2024
+
2025
+ #### 2.6.4 FlexboxLayout 属性映射统计
2026
+
2027
+ | 映射类型 | 数量 | 占比 |
2028
+ |---------|------|------|------|
2029
+ | 直接映射 | 6 | ~15% |
2030
+ | 需类型转换 | 4 | ~25% |
2031
+ | 需组合实现 | 8 | ~50% |
2032
+ | 无直接对应 | 5 | ~14% |
2033
+ | **总计** | **23** | **100%** |
2034
+
2035
+ ---
2036
+
2037
+ ### 2.7 协调布局
2038
+
2039
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2040
+ |-------------|------|---------------|---------|------|
2041
+ | CoordinatorLayout | `androidx.coordinatorlayout.widget.CoordinatorLayout` | 自定义组合 | 需业务实现 | 协调布局 |
2042
+ | AppBarLayout | `com.google.android.material.appbar.AppBarLayout` | 自定义组合 | Column + 手势 | 应用栏布局 |
2043
+ | CollapsingToolbarLayout | `com.google.android.material.appbar.CollapsingToolbarLayout` | 自定义组合 | Column + 动画 | 折叠工具栏布局 |
2044
+
2045
+ ### 2.8 抽屉布局
2046
+
2047
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2048
+ |-------------|------|---------------|---------|------|
2049
+ | DrawerLayout | `androidx.drawerlayout.widget.DrawerLayout` | `Sheet` / 自定义 | 侧滑抽屉 | 抽屉布局 |
2050
+ | SlidingPaneLayout | `androidx.slidingpanelayout.widget.SlidingPaneLayout` | 自定义组合 | Panel + 动画 | 滑动面板布局 |
2051
+
2052
+ ### 2.9 刷新布局
2053
+
2054
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2055
+ |-------------|------|---------------|---------|------|
2056
+ | SwipeRefreshLayout | `androidx.swiperefreshlayout.widget.SwipeRefreshLayout` | `Refresh` | 直接映射 | 下拉刷新布局 |
2057
+
2058
+ ---
2059
+
2060
+ ## 三、列表与适配器组件映射
2061
+
2062
+ ### 3.1 列表视图
2063
+
2064
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2065
+ |-------------|------|---------------|---------|------|
2066
+ | ListView | `android.widget.ListView` | `List` | 高性能列表 | 列表视图(已废弃) |
2067
+ | ExpandableListView | `android.widget.ExpandableListView` | `List` + `ListItemGroup` | 配合展开逻辑 | 可展开列表视图 |
2068
+ | ListPopupWindow | `android.widget.ListPopupWindow` | `Popup` + `List` | 组合实现 | 列表弹出窗口 |
2069
+
2070
+ ### 3.2 RecyclerView 系列
2071
+
2072
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2073
+ |-------------|------|---------------|---------|------|
2074
+ | RecyclerView | `androidx.recyclerview.widget.RecyclerView` | `List` | 配合 LazyForEach | 高性能列表视图 |
2075
+ | RecyclerView.Adapter | `androidx.recyclerview.widget.RecyclerView.Adapter` | `LazyForEach` | 数据源管理 | 列表适配器 |
2076
+ | RecyclerView.ViewHolder | `androidx.recyclerview.widget.RecyclerView.ViewHolder` | `ListItem` | 列表项组件 | 列表项持有者 |
2077
+ | LinearLayoutManager | `androidx.recyclerview.widget.LinearLayoutManager` | `List` | listDirection 配置 | 线性布局管理器 |
2078
+ | GridLayoutManager | `androidx.recyclerview.widget.GridLayoutManager` | `Grid` | 网格布局 | 网格布局管理器 |
2079
+ | StaggeredGridLayoutManager | `androidx.recyclerview.widget.StaggeredGridLayoutManager` | `WaterFlow` | 瀑布流布局 | 瀑布流布局管理器 |
2080
+ | ItemTouchHelper | `androidx.recyclerview.widget.ItemTouchHelper` | 拖拽 API | Drag + Drop | 列表项触摸辅助 |
2081
+ | SnapHelper | `androidx.recyclerview.widget.SnapHelper` | 自定义对齐逻辑 | 手势实现 | 对齐辅助 |
2082
+ | LinearSnapHelper | `androidx.recyclerview.widget.LinearSnapHelper` | 自定义对齐逻辑 | Swiper 配合 | 线性对齐辅助 |
2083
+ | PagerSnapHelper | `androidx.recyclerview.widget.PagerSnapHelper` | `Swiper` | 轮播容器 | 分页对齐辅助 |
2084
+
2085
+ ### 3.3 适配器视图基类
2086
+
2087
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2088
+ |-------------|------|---------------|---------|------|
2089
+ | AdapterView | `android.widget.AdapterView` | 基础架构概念 | 适配器视图基类 | 适配器视图基类 |
2090
+ | AdapterViewAnimator | `android.widget.AdapterViewAnimator` | 自定义动画组件 | transition | 适配器视图动画器 |
2091
+ | AdapterViewFlipper | `android.widget.AdapterViewFlipper` | `Swiper` | 轮播切换 | 适配器视图翻转器 |
2092
+ | StackView | `android.widget.StackView` | `Stack` | 堆叠布局 | 堆栈视图 |
2093
+
2094
+ ---
2095
+
2096
+ ## 四、切换与翻页组件映射
2097
+
2098
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2099
+ |-------------|------|---------------|---------|------|
2100
+ | ViewPager | `androidx.viewpager.widget.ViewPager` | `Swiper` | 轮播容器 | 页面切换器(已废弃) |
2101
+ | ViewPager2 | `androidx.viewpager2.widget.ViewPager2` | `Swiper` | 轮播容器 | 页面切换器 |
2102
+ | TabHost | `android.widget.TabHost` | `Tabs` + `TabContent` | 已废弃 | 标签页主机(已废弃) |
2103
+ | TabWidget | `android.widget.TabWidget` | `Tabs` | 已废弃 | 标签页组件(已废弃) |
2104
+ | ViewFlipper | `android.widget.ViewFlipper` | `Swiper` | 轮播切换 | 视图翻转器 |
2105
+ | ViewSwitcher | `android.widget.ViewSwitcher` | `Swiper` | 轮播切换 | 视图切换器 |
2106
+ | ImageSwitcher | `android.widget.ImageSwitcher` | `Swiper` + `Image` | 配合 Image | 图片切换器 |
2107
+ | TextSwitcher | `android.widget.TextSwitcher` | `Swiper` + `Text` | 配合 Text | 文本切换器 |
2108
+
2109
+ ---
2110
+
2111
+ ## 五、Material Design 组件映射
2112
+
2113
+ ### 5.1 Material 按钮
2114
+
2115
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2116
+ |-------------|------|---------------|---------|------|
2117
+ | MaterialButton | `com.google.android.material.button.MaterialButton` | `Button` | 配置样式 | Material 按钮 |
2118
+ | IconButton | `com.google.android.material.button.MaterialButton` | `Button` + 图标 | 组合实现 | 图标按钮 |
2119
+ | SplitButton | `com.google.android.material.button.MaterialButtonGroup` | `Row` + 2个 `Button` | 组合实现 | 分割按钮 |
2120
+ | ToggleButton | `com.google.android.material.button.MaterialButtonToggleGroup` | `RadioContainer` | 配合 Radio | 切换按钮组 |
2121
+
2122
+ ### 5.2 Material 文本输入
2123
+
2124
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2125
+ |-------------|------|---------------|---------|------|
2126
+ | TextInputLayout | `com.google.android.material.textfield.TextInputLayout` | `Column` + `TextInput` + 样式 | 组合实现 | 文本输入布局 |
2127
+ | TextInputEditText | `com.google.android.material.textfield.TextInputEditText` | `TextInput` | 配置样式 | 文本输入框 |
2128
+ | ExposedDropdownMenu | `com.google.android.material.textfield.MaterialAutoCompleteTextView` | `Select` | 下拉选择 | 暴露下拉菜单 |
2129
+
2130
+ ### 5.3 Material 卡片
2131
+
2132
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2133
+ |-------------|------|---------------|---------|------|
2134
+ | CardView | `androidx.cardview.widget.CardView` | `Column` + 样式 | borderRadius + shadow | 卡片视图 |
2135
+ | MaterialCardView | `com.google.android.material.card.MaterialCardView` | `Column` + 样式 | borderRadius + shadow | Material 卡片 |
2136
+
2137
+ ### 5.4 Material 底部组件
2138
+
2139
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2140
+ |-------------|------|---------------|---------|------|
2141
+ | BottomNavigationView | `com.google.android.material.bottomnavigation.BottomNavigationView` | `Tabs` | 配合路由 | 底部导航 |
2142
+ | BottomSheetDialog | `com.google.android.material.bottomsheet.BottomSheetDialog` | `Sheet` | 底部抽屉 | 底部抽屉对话框 |
2143
+ | BottomSheetDialogFragment | `com.google.android.material.bottomsheet.BottomSheetDialogFragment` | `Sheet` | 配合路由 | 底部抽屉片段 |
2144
+ | BottomSheetBehavior | `com.google.android.material.bottomsheet.BottomSheetBehavior` | `Sheet` | 配置行为 | 底部抽屉行为 |
2145
+
2146
+ ### 5.5 Material 导航组件
2147
+
2148
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2149
+ |-------------|------|---------------|---------|------|
2150
+ | NavigationView | `com.google.android.material.navigation.NavigationView` | 自定义组合 | Column + 列表 | 导航视图 |
2151
+ | NavigationRailView | `com.google.android.material.navigationrail.NavigationRailView` | 自定义组合 | Column + 垂直列表 | 导航栏 |
2152
+ | TabLayout | `com.google.android.material.tabs.TabLayout` | `Tabs` | 直接映射 | 标签页布局 |
2153
+ | TabItem | `com.google.android.material.tabs.TabItem` | `TabContent` | 配合 Tabs | 标签页项 |
2154
+
2155
+ ### 5.6 Material 浮动组件
2156
+
2157
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2158
+ |-------------|------|---------------|---------|------|
2159
+ | FloatingActionButton | `com.google.android.material.floatingactionbutton.FloatingActionButton` | `Button` + 样式 | 圆形 + 阴影 | 浮动操作按钮 |
2160
+ | ExtendedFloatingActionButton | `com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton` | `Button` + 样式 | 长按钮 | 扩展浮动按钮 |
2161
+ | SpeedDial | `com.google.android.material.floatingactionbutton.FloatingActionButton` | 自定义组合 | 多个 FAB | 快捷拨号(组合实现) |
2162
+
2163
+ ### 5.7 Material 对话框
2164
+
2165
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2166
+ |-------------|------|---------------|---------|------|
2167
+ | AlertDialog | `androidx.appcompat.app.AlertDialog` | `AlertDialog` | 直接映射 | 警告对话框 |
2168
+ | MaterialAlertDialogBuilder | `com.google.android.material.dialog.MaterialAlertDialogBuilder` | `AlertDialog` | 配置 Material 样式 | Material 对话框构建器 |
2169
+ | DatePickerDialog | `android.app.DatePickerDialog` | `DatePickerDialog` | 直接映射 | 日期选择对话框 |
2170
+ | TimePickerDialog | `android.app.TimePickerDialog` | `TimePickerDialog` | 直接映射 | 时间选择对话框 |
2171
+ | ProgressDialog | `android.app.ProgressDialog` | `LoadingDialog` | 已废弃 | 进度对话框(已废弃) |
2172
+
2173
+ ### 5.8 Material 提示组件
2174
+
2175
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2176
+ |-------------|------|---------------|---------|------|
2177
+ | Snackbar | `com.google.android.material.snackbar.Snackbar` | 自定义组合 | Toast + 样式 | 快速提示条 |
2178
+ | Toast | `android.widget.Toast` | `prompt.showToast()` | API 调用 | 吐司提示 |
2179
+ | Tooltip | `com.google.android.material.tooltip.TooltipDrawable` | 暂无直接对应 | 自定义 Popup | 工具提示 |
2180
+
2181
+ ### 5.9 Material 菜单组件
2182
+
2183
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2184
+ |-------------|------|---------------|---------|------|
2185
+ | PopupMenu | `android.widget.PopupMenu` | `Menu` / `BindMenu` | 直接映射 | 弹出菜单 |
2186
+ | PopupWindow | `android.widget.PopupWindow` | `Popup` | 直接映射 | 弹出窗口 |
2187
+ | DropdownMenu | `com.google.android.material.menu.MaterialMenuView` | `Select` | 下拉选择 | 下拉菜单 |
2188
+
2189
+ ### 5.10 Material 进度指示器
2190
+
2191
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2192
+ |-------------|------|---------------|---------|------|
2193
+ | CircularProgressIndicator | `com.google.android.material.progressindicator.CircularProgressIndicator` | `Progress` (type: CircularProgressType) | 配置类型 | 圆形进度指示器 |
2194
+ | LinearProgressIndicator | `com.google.android.material.progressindicator.LinearProgressIndicator` | `Progress` | 配置类型 | 线性进度指示器 |
2195
+
2196
+ ### 5.11 Material 滑块与范围
2197
+
2198
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2199
+ |-------------|------|---------------|---------|------|
2200
+ | Slider | `com.google.android.material.slider.Slider` | `Slider` | 直接映射 | 滑块 |
2201
+ | RangeSlider | `com.google.android.material.slider.RangeSlider` | 暂无直接对应 | 自定义双 Slider | 范围滑块 |
2202
+
2203
+ ### 5.12 Material Chips
2204
+
2205
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2206
+ |-------------|------|---------------|---------|------|
2207
+ | Chip | `com.google.android.material.chip.Chip` | 自定义组合 | Row + 样式 | 芯片标签 |
2208
+ | ChipGroup | `com.google.android.material.chip.ChipGroup` | `CheckboxGroup` / `Flex` | 配合 Chip | 芯片组 |
2209
+ | ChipDrawable | `com.google.android.material.chip.ChipDrawable` | 自定义样式 | @Styles | 芯片绘制 |
2210
+
2211
+ ### 5.13 Material 顶部应用栏
2212
+
2213
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2214
+ |-------------|------|---------------|---------|------|
2215
+ | Toolbar | `androidx.appcompat.widget.Toolbar` | 自定义组合 | Row + 按钮 | 工具栏 |
2216
+ | MaterialToolbar | `com.google.android.material.appbar.MaterialToolbar` | 自定义组合 | Row + 样式 | Material 工具栏 |
2217
+ | SearchBar | `com.google.android.material.search.SearchBar` | `Search` | 配置样式 | 搜索栏 |
2218
+ | SearchView | `com.google.android.material.search.SearchView` | `Search` | 配置样式 | 搜索视图 |
2219
+
2220
+ ### 5.14 Material 骨架屏
2221
+
2222
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2223
+ |-------------|------|---------------|---------|------|
2224
+ | ShimmerFrameLayout | `com.facebook.shimmer.ShimmerFrameLayout` | 暂无直接对应 | 自定义动画 | 骨架屏动画(Facebook) |
2225
+ | SkeletonLayout | 第三方库 | 暂无直接对应 | 自定义加载占位 | 骨架屏布局 |
2226
+
2227
+ ---
2228
+
2229
+ ## 六、Jetpack Compose 组件映射
2230
+
2231
+ ### 6.1 Compose 基础组件
2232
+
2233
+ | Android Compose | 函数名 | HarmonyOS 组件 | 替代方案 | 说明 |
2234
+ |----------------|--------|---------------|---------|------|
2235
+ | Text | `Text()` | `Text` | 直接映射 | 文本显示 |
2236
+ | TextField | `TextField()` / `OutlinedTextField()` | `TextInput` | 配置样式 | 文本输入框 |
2237
+ | BasicTextField | `BasicTextField()` | `TextInput` | 基础配置 | 基础文本输入 |
2238
+ | Button | `Button()` | `Button` | 直接映射 | 按钮 |
2239
+ | IconButton | `IconButton()` | `Button` + 图标 | 组合实现 | 图标按钮 |
2240
+ | Icon | `Icon()` | `SymbolGlyph` / `Image` | 系统图标或图片 | 图标 |
2241
+ | Image | `Image()` | `Image` | 直接映射 | 图片 |
2242
+ | Checkbox | `Checkbox()` | `Checkbox` | 直接映射 | 复选框 |
2243
+ | RadioButton | `RadioButton()` | `Radio` | 配合容器 | 单选按钮 |
2244
+ | Switch | `Switch()` | `Toggle` (Switch) | 直接映射 | 开关 |
2245
+ | Slider | `Slider()` | `Slider` | 直接映射 | 滑块 |
2246
+ | RangeSlider | `RangeSlider()` | 暂无直接对应 | 自定义双 Slider | 范围滑块 |
2247
+
2248
+ ### 6.2 Compose 布局组件
2249
+
2250
+ | Android Compose | 函数名 | HarmonyOS 组件 | 替代方案 | 说明 |
2251
+ |----------------|--------|---------------|---------|------|
2252
+ | Column | `Column()` | `Column` | 直接映射 | 垂直线性布局 |
2253
+ | Row | `Row()` | `Row` | 直接映射 | 水平线性布局 |
2254
+ | Box | `Box()` | `Stack` | 直接映射 | 堆叠布局 |
2255
+ | ConstraintLayout | `ConstraintLayout()` | `RelativeContainer` | 部分对应 | 约束布局 |
2256
+ | FlowRow | `FlowRow()` | `Flex` (direction: Row) | 流式行布局 | 流式行布局 |
2257
+ | FlowColumn | `FlowColumn()` | `Flex` (direction: Column) | 流式列布局 | 流式列布局 |
2258
+ | LazyColumn | `LazyColumn()` | `List` (listDirection: Axis.Vertical) | 配合 LazyForEach | 懒加载垂直列表 |
2259
+ | LazyRow | `LazyRow()` | `List` (listDirection: Axis.Horizontal) | 配合 LazyForEach | 懒加载水平列表 |
2260
+ | LazyVerticalGrid | `LazyVerticalGrid()` | `Grid` + LazyForEach | 网格懒加载 | 懒加载垂直网格 |
2261
+ | LazyHorizontalGrid | `LazyHorizontalGrid()` | `Grid` + LazyForEach | 网格懒加载 | 懒加载水平网格 |
2262
+ | GridLayout | `GridLayout()` | `GridRow` + `GridCol` | 栅格系统 | 网格布局 |
2263
+
2264
+ ### 6.3 Compose Material 3 组件
2265
+
2266
+ | Android Compose | 函数名 | HarmonyOS 组件 | 替代方案 | 说明 |
2267
+ |----------------|--------|---------------|---------|------|
2268
+ | Card | `Card()` / `ElevatedCard()` / `OutlinedCard()` | `Column` + 样式 | 卡片 |
2269
+ | FloatingActionButton | `FloatingActionButton()` / `ExtendedFloatingActionButton()` | `Button` + 样式 | 浮动按钮 |
2270
+ | Chip | `Chip()` / `InputChip()` / `FilterChip()` / `SuggestionChip()` | 自定义组合 | Row + 样式 | 芯片 |
2271
+ | NavigationBar | `NavigationBar()` | `Tabs` | 配合路由 | 底部导航栏 |
2272
+ | NavigationRail | `NavigationRail()` | 自定义组合 | 垂直导航 | 侧边导航栏 |
2273
+ | NavigationDrawer | `ModalNavigationDrawer()` | `Sheet` / 自定义 | 导航抽屉 | 模态导航抽屉 |
2274
+ | TabRow | `TabRow()` / `ScrollableTabRow()` | `Tabs` | 直接映射 | 标签页行 |
2275
+ | BottomSheet | `BottomSheetScaffold()` | `Sheet` | 直接映射 | 底部抽屉 |
2276
+ | Snackbar | `Snackbar()` / `SnackbarHost()` | 自定义组合 | Toast + 样式 | 快速提示 |
2277
+ | TopAppBar | `TopAppBar()` / `CenterAlignedTopAppBar()` / `MediumTopAppBar()` / `LargeTopAppBar()` | 自定义组合 | Row + 样式 | 顶部应用栏 |
2278
+ | AlertDialog | `AlertDialog()` | `AlertDialog` | 直接映射 | 警告对话框 |
2279
+ | DatePicker | `DatePicker()` | `DatePicker` | 直接映射 | 日期选择器 |
2280
+ | ProgressIndicator | `CircularProgressIndicator()` / `LinearProgressIndicator()` | `Progress` | 配置类型 | 进度指示器 |
2281
+ | PullRefresh | `PullRefreshIndicator()` | `Refresh` | 直接映射 | 下拉刷新 |
2282
+ | SwipeToDismiss | `SwipeToDismiss()` | 暂无直接对应 | 拖拽 API + 状态 | 滑动删除 |
2283
+
2284
+ ### 6.4 Compose 动画组件
2285
+
2286
+ | Android Compose | 函数名 | HarmonyOS 组件 | 替代方案 | 说明 |
2287
+ |----------------|--------|---------------|---------|------|
2288
+ | AnimatedVisibility | `AnimatedVisibility()` | `transition` + `animateTo` | 动画可见性 |
2289
+ | AnimatedContent | `AnimatedContent()` | `transition` + `animateTo` | 动画内容切换 |
2290
+ | Crossfade | `Crossfade()` | `animateTo` (opacity) | 淡入淡出 |
2291
+ | animateAsState | `animate*AsState()` | `animateTo` | 状态动画 |
2292
+ | AnimatedValue | `animateFloatAsState()` 等 | `animateTo` | 值动画 |
2293
+
2294
+ ---
2295
+
2296
+ ## 七、特殊视图组件映射
2297
+
2298
+ ### 7.1 网页视图
2299
+
2300
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2301
+ |-------------|------|---------------|---------|------|
2302
+ | WebView | `android.webkit.WebView` | `Web` | 直接映射 | 网页视图 |
2303
+
2304
+ ### 7.2 表面视图
2305
+
2306
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2307
+ |-------------|------|---------------|---------|------|
2308
+ | SurfaceView | `android.view.SurfaceView` | `XComponent` | OpenGL 渲染 | 表面视图(独立绘图线程) |
2309
+ | TextureView | `android.view.TextureView` | `XComponent` | 原生渲染 | 纹理视图(支持动画变换) |
2310
+ | GLSurfaceView | `android.opengl.GLSurfaceView` | `XComponent` | OpenGL 渲染 | OpenGL 表面视图 |
2311
+
2312
+ ### 7.3 自定义组件
2313
+
2314
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2315
+ |-------------|------|---------------|---------|------|
2316
+ | View | `android.view.View` | `@Component` | 自定义组件 | 视图基类 |
2317
+ | ViewGroup | `android.view.ViewGroup` | 容器组件 | Row/Column/Stack 等 | 视图组基类 |
2318
+
2319
+ ### 7.4 通知组件
2320
+
2321
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2322
+ |-------------|------|---------------|---------|------|
2323
+ | RemoteViews | `android.widget.RemoteViews` | 暂无直接对应 | 通知 API | 远程视图(用于通知、桌面小部件) |
2324
+ | AppWidgetHostView | `android.appwidget.AppWidgetHostView` | 暂无直接对应 | 桌面小部件 API | 应用小部件宿主视图 |
2325
+
2326
+ ---
2327
+
2328
+ ## 八、辅助组件映射
2329
+
2330
+ ### 8.1 视图辅助
2331
+
2332
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2333
+ |-------------|------|---------------|---------|------|
2334
+ | ViewStub | `android.view.ViewStub` | 暂无直接对应 | 条件渲染 + Lazy | 延迟加载视图 |
2335
+ | Space | `android.widget.Space` | `Row`/`Column` 空子项 | 布局技巧 | 空白占位 |
2336
+ | ViewOutlineProvider | `android.view.ViewOutlineProvider` | 暂无直接对应 | clipShape API | 视图轮廓提供者 |
2337
+
2338
+ ### 8.2 手势组件
2339
+
2340
+ | Android 组件 | 类名 | HarmonyOS 组件 | 替代方案 | 说明 |
2341
+ |-------------|------|---------------|---------|------|
2342
+ | GestureDetector | `android.view.GestureDetector` | 手势 API 组合 | TapGesture/PanGesture 等 | 手势检测器 |
2343
+ | ScaleGestureDetector | `android.view.ScaleGestureDetector` | `PinchGesture` | 直接映射 | 缩放手势检测器 |
2344
+
2345
+ ---
2346
+
2347
+ ## 九、布局属性映射(API 20/21)
2348
+
2349
+ ### 9.1 尺寸属性
2350
+
2351
+ | Android XML | HarmonyOS | 说明 | 代码示例对比 |
2352
+ |-------------|-----------|------|-------------|
2353
+ | layout_width | width | 宽度 | Android: `android:layout_width="100dp"`<br/>HarmonyOS: `Component().width(100)` |
2354
+ | layout_height | height | 高度 | Android: `android:layout_height="match_parent"`<br/>HarmonyOS: `Component().height('100%')` |
2355
+ | minWidth | constraintSize({ minWidth: value }) | 最小宽度 | Android: `android:minWidth="100dp"`<br/>HarmonyOS: `Component().constraintSize({ minWidth: 100 })` |
2356
+ | maxWidth | constraintSize({ maxWidth: value }) | 最大宽度 | Android: `android:maxWidth="200dp"`<br/>HarmonyOS: `Component().constraintSize({ maxWidth: 200 })` |
2357
+ | minHeight | constraintSize({ minHeight: value }) | 最小高度 | Android: `android:minHeight="50dp"`<br/>HarmonyOS: `Component().constraintSize({ minHeight: 50 })` |
2358
+ | maxHeight | constraintSize({ maxHeight: value }) | 最大高度 | Android: `android:maxHeight="300dp"`<br/>HarmonyOS: `Component().constraintSize({ maxHeight: 300 })` |
2359
+ | layout_weight | layoutWeight | 布局权重 | Android: `android:layout_weight="1"`<br/>HarmonyOS: `Component().layoutWeight(1)` |
2360
+
2361
+ ### 9.2 边距与内边距
2362
+
2363
+ | Android XML | HarmonyOS | 说明 | 代码示例对比 |
2364
+ |-------------|-----------|------|-------------|
2365
+ | layout_margin | margin | 外边距 | Android: `android:layout_margin="10dp"`<br/>HarmonyOS: `Component().margin(10)` |
2366
+ | layout_marginTop | margin({ top: value }) | 上边距 | Android: `android:layout_marginTop="10dp"`<br/>HarmonyOS: `Component().margin({ top: 10 })` |
2367
+ | layout_marginBottom | margin({ bottom: value }) | 下边距 | Android: `android:layout_marginBottom="10dp"`<br/>HarmonyOS: `Component().margin({ bottom: 10 })` |
2368
+ | layout_marginLeft | margin({ left: value }) | 左边距 | Android: `android:layout_marginLeft="10dp"`<br/>HarmonyOS: `Component().margin({ left: 10 })` |
2369
+ | layout_marginRight | margin({ right: value }) | 右边距 | Android: `android:layout_marginRight="10dp"`<br/>HarmonyOS: `Component().margin({ right: 10 })` |
2370
+ | layout_marginStart | margin({ start: value }) | 起始边距 | Android: `android:layout_marginStart="10dp"`<br/>HarmonyOS: `Component().margin({ start: 10 })` |
2371
+ | layout_marginEnd | margin({ end: value }) | 结束边距 | Android: `android:layout_marginEnd="10dp"`<br/>HarmonyOS: `Component().margin({ end: 10 })` |
2372
+ | padding | padding | 内边距 | Android: `android:padding="10dp"`<br/>HarmonyOS: `Component().padding(10)` |
2373
+ | paddingTop | padding({ top: value }) | 上内边距 | Android: `android:paddingTop="10dp"`<br/>HarmonyOS: `Component().padding({ top: 10 })` |
2374
+ | paddingBottom | padding({ bottom: value }) | 下内边距 | Android: `android:paddingBottom="10dp"`<br/>HarmonyOS: `Component().padding({ bottom: 10 })` |
2375
+
2376
+ ### 9.3 对齐与权重
2377
+
2378
+ | Android XML | HarmonyOS | 说明 | 代码示例对比 |
2379
+ |-------------|-----------|------|-------------|
2380
+ | layout_gravity | align / alignSelf | 对齐方式 | Android: `android:layout_gravity="center"`<br/>HarmonyOS: `Component().align(Alignment.Center)` |
2381
+ | gravity | textAlign | 文本对齐 | Android: `android:gravity="center"`<br/>HarmonyOS: `Text().textAlign(TextAlign.Center)` |
2382
+ | layout_weight | layoutWeight | 权重 | Android: `android:layout_weight="1"`<br/>HarmonyOS: `Component().layoutWeight(1)` |
2383
+
2384
+ ### 9.4 显示属性
2385
+
2386
+ | Android XML | HarmonyOS | 说明 | 代码示例对比 |
2387
+ |-------------|-----------|------|-------------|
2388
+ | visibility | visibility | 可见性 | Android: `android:visibility="gone"`<br/>HarmonyOS: `Component().visibility(Visibility.None)` |
2389
+ | alpha | opacity | 透明度 | Android: `android:alpha="0.5"`<br/>HarmonyOS: `Component().opacity(0.5)` |
2390
+ | background | backgroundColor | 背景色 | Android: `android:background="#FF0000FF"`<br/>HarmonyOS: `Component().backgroundColor('#FF0000FF')` |
2391
+ | background | backgroundImage | 背景图 | Android: `android:background="@drawable/bg"`<br/>HarmonyOS: `Component().backgroundImage($r('app.media.bg'))` |
2392
+ | foreground | 无直接对应 | 前景图 | Android: `android:foreground`<br/>HarmonyOS: 无直接对应,需组合实现 |
2393
+
2394
+ ### 9.5 边框与圆角
2395
+
2396
+ | Android XML | HarmonyOS | 说明 | 代码示例对比 |
2397
+ |-------------|-----------|------|-------------|
2398
+ | elevation | shadow | 阴影效果 | Android: `android:elevation="10dp"`<br/>HarmonyOS: `Component().shadow({ radius: 10, color: '#80000000', offsetX: 0, offsetY: 5 })` |
2399
+ | cardElevation | shadow | 卡片阴影 | Android: Material 卡片属性<br/>HarmonyOS: `Column().shadow({ radius: 8, color: '#30000000' })` |
2400
+
2401
+ ### 9.6 变换属性
2402
+
2403
+ | Android XML | HarmonyOS | 说明 | 代码示例对比 |
2404
+ |-------------|-----------|------|-------------|
2405
+ | rotation | rotate | 旋转角度 | Android: `android:rotation="90"`<br/>HarmonyOS: `Component().rotate({ angle: 90 })` |
2406
+ | scaleX / scaleY | scale({ x, y }) | 缩放 | Android: `android:scaleX="1.5"`<br/>HarmonyOS: `Component().scale({ x: 1.5, y: 1 })` |
2407
+ | translationX / translationY | translate({ x, y }) | 平移 | Android: `android:translationX="100"`<br/>HarmonyOS: `Component().translate({ x: 100 })` |
2408
+ | pivotX / pivotY | 无直接对应 | 旋转中心点 | Android: `android:pivotX="0.5"`<br/>HarmonyOS: 无直接对应 |
2409
+
2410
+ ### 9.7 交互属性
2411
+
2412
+ | Android XML | HarmonyOS | 说明 | 代码示例对比 |
2413
+ |-------------|-----------|------|-------------|
2414
+ | clickable | enabled / enabled | 是否可点击 | Android: `android:clickable="true"`<br/>HarmonyOS: `Component().enabled(true)` |
2415
+ | focusable | focusable | 是否可获取焦点 | Android: `android:focusable="true"`<br/>HarmonyOS: `Component().focusable(true)` |
2416
+ | clickable | enabled / enabled | 是否可交互 | Android: `android:clickable="true"`<br/>HarmonyOS: `Component().enabled(true)` |
2417
+
2418
+ ### 9.8 单位换算(API 20/21)
2419
+
2420
+ | Android | HarmonyOS | 换算关系 | 说明 |
2421
+ |---------|-----------|---------|------|
2422
+ | dp | vp | 密度无关像素 | Android: `16dp` ≈ HarmonyOS: `16vp` |
2423
+ | sp | fp | 字体像素 | Android: `16sp` ≈ HarmonyOS: `16fp` |
2424
+ | px | px | 像素 | Android: `16px` = HarmonyOS: `16px` |
2425
+
2426
+ ---
2427
+
2428
+ ## 十、未找到直接对应方案的 Android 组件
2429
+
2430
+ 以下 Android 组件在 HarmonyOS ArkUI 中暂无直接对应组件,需要通过组合实现、自定义开发或使用特定 Kit 替代:
2431
+
2432
+ | Android 组件 | 类名 | HarmonyOS 替代方案 | 难度等级 | 说明 |
2433
+ |-------------|------|------------------|---------|------|
2434
+ | **ConstraintLayout 辅助组件** | | | | |
2435
+ | Guideline | `androidx.constraintlayout.widget.Guideline` | 借助 Absolute 定位 | 中等 | 需手动计算和约束 |
2436
+ | Barrier | `androidx.constraintlayout.widget.Barrier` | 手动计算位置 | 中等 | 需监听子组件尺寸变化 |
2437
+ | Group | `androidx.constraintlayout.widget.Group` | 批量操作逻辑 | 简单 | 需要手动管理引用 |
2438
+ | Placeholder | `androidx.constraintlayout.widget.Placeholder` | 动态替换 | 中等 | 需要状态管理 |
2439
+ | **Material 3 特殊组件** | | | | |
2440
+ | RangeSlider | `com.google.android.material.slider.RangeSlider` | 自定义双 Slider | 中等 | 需同步两个 Slider 状态 |
2441
+ | ShimmerFrameLayout | `com.facebook.shimmer.ShimmerFrameLayout` | 自定义动画 | 简单 | 使用 animateTo + opacity |
2442
+ | Tooltip | `com.google.android.material.tooltip.TooltipDrawable` | 自定义 Popup | 中等 | 长按触发 Popup |
2443
+ | Chip | `com.google.android.material.chip.Chip` | 自定义组合 | 简单 | Row + 样式 + 点击逻辑 |
2444
+ | **协调布局组件** | | | | |
2445
+ | CoordinatorLayout | `androidx.coordinatorlayout.widget.CoordinatorLayout` | 自定义组合 | 困难 | 需要复杂的嵌套滚动协调 |
2446
+ | AppBarLayout | `com.google.android.material.appbar.AppBarLayout` | 自定义组合 | 中等 | 需要滚动联动逻辑 |
2447
+ | CollapsingToolbarLayout | `com.google.android.material.appbar.CollapsingToolbarLayout` | 自定义组合 | 困难 | 需要滚动高度计算 + 动画 |
2448
+ | **抽屉布局** | | | | |
2449
+ | DrawerLayout | `androidx.drawerlayout.widget.DrawerLayout` | Sheet / 自定义 | 中等 | 侧滑手势需要自定义 |
2450
+ | SlidingPaneLayout | `androidx.slidingpanelayout.widget.SlidingPaneLayout` | 自定义组合 | 中等 | Panel + 动画 + 滑动手势 |
2451
+ | **通知与小部件** | | | | |
2452
+ | RemoteViews | `android.widget.RemoteViews` | 通知 Kit | 困难 | 桌面小部件暂不支持 |
2453
+ | AppWidgetHostView | `android.appwidget.AppWidgetHostView` | 暂不支持 | 不可行 | HarmonyOS 没有桌面小部件系统 |
2454
+ | **Jetpack Compose 特有** | | | | |
2455
+ | SwipeToDismiss | `SwipeToDismiss()` | 拖拽 API + 状态 | 中等 | 需要配合 PanGesture + 状态管理 |
2456
+ | **其他特殊组件** | | | | |
2457
+ | DialerFilter | `android.widget.DialerFilter` | 自定义业务组件 | 中等 | 需要具体的拨号逻辑 |
2458
+ | ViewStub | `android.view.ViewStub` | 条件渲染 + Lazy | 简单 | 使用 if/else + LazyForEach |
2459
+ | ViewOutlineProvider | `android.view.ViewOutlineProvider` | clipShape API | 中等 | 使用通用属性中的裁剪 |
2460
+ | MotionLayout | `androidx.constraintlayout.motion.widget.MotionLayout` | 动画 API 组合 | 困难 | animateTo + transition + 状态管理 |
2461
+
2462
+ ---
2463
+
2464
+ ## 十、映射方案总结
2465
+
2466
+ ### 10.1 完全直接映射的组件(70+)
2467
+
2468
+ 可以直接一对一替换的组件:
2469
+ - 基础组件:Text、Button、Image、Checkbox、Radio、Slider、Rating 等
2470
+ - 布局组件:Row、Column、Flex、Stack、Grid、List 等
2471
+ - 选择器:DatePicker、TimePicker、CalendarPicker、Select 等
2472
+ - 弹窗:AlertDialog、ActionSheet、LoadingDialog 等
2473
+ - 功能组件:Web、Video、Search、Divider 等
2474
+
2475
+ ### 10.2 需要组合实现的组件(50+)
2476
+
2477
+ 需要通过多个 HarmonyOS 组件组合实现的 Android 组件:
2478
+ - ImageButton → Button + Image
2479
+ - ImageView 带文本 → Row + Image + Text
2480
+ - Material 组件 → 容器组件 + 样式配置
2481
+ - 复杂列表 → List + ListItemGroup + LazyForEach
2482
+
2483
+ ### 10.3 需要自定义实现的组件(20+)
2484
+
2485
+ 需要编写自定义逻辑或组件的 Android 组件:
2486
+ - CoordinatorLayout 及相关 → 复杂滚动协调逻辑
2487
+ - Material 特效组件 → 动画 API + 状态管理
2488
+ - 通知/小部件 → 暂不支持,需替代方案
2489
+ - ConstraintLayout 高级辅助 → 手动计算和约束
2490
+
2491
+ ### 10.4 完全不支持的组件(5+)
2492
+
2493
+ 在 HarmonyOS 中无法实现的 Android 组件:
2494
+ - 桌面小部件系统 → HarmonyOS 架构不同
2495
+ - 部分通知交互 → 通知 Kit 能力有限
2496
+ - Material MotionLayout 部分功能 → 需要手动实现
2497
+
2498
+ ---
2499
+
2500
+ ## 十一、迁移建议
2501
+
2502
+ ### 11.1 优先级排序
2503
+
2504
+ 1. **高优先级**(完全支持):基础 UI 组件、布局容器、列表组件
2505
+ 2. **中优先级**(部分支持):Material 组件、复杂动画、自定义布局
2506
+ 3. **低优先级**(暂不支持):小部件、高级动画、特殊交互
2507
+
2508
+ ### 11.2 迁移策略
2509
+
2510
+ 1. **渐进式迁移**:先迁移基础功能,再处理复杂交互
2511
+ 2. **组件降级**:Material 组件可降级为基础组件 + 样式
2512
+ 3. **功能替代**:无直接对应的组件用功能相似的组合替代
2513
+ 4. **自定义开发**:关键但缺失的组件需要自定义实现
2514
+
2515
+ ### 11.3 注意事项
2516
+
2517
+ 1. HarmonyOS 声明式 UI 与 Android 命令式 UI 有本质区别
2518
+ 2. 状态管理是 HarmonyOS 的核心,需熟练掌握 @State/@Link 等装饰器
2519
+ 3. 布局参数从 XML 属性改为链式调用,语法差异较大
2520
+ 4. 事件处理从监听器改为回调函数,编程范式不同
2521
+ 5. 部分高级功能(如 MotionLayout、小部件)需要重新设计架构
2522
+
2523
+ ---
2524
+
2525
+ ## 参考链接
2526
+
2527
+ 1. **Android UI 组件全量清单**: `/docs/android-ui-components-full-list.md`
2528
+ 2. **HarmonyOS ArkUI 组件全量清单**: `/docs/harmonyos-arkui-components-full-list.md`
2529
+ 3. **HarmonyOS 开发者文档**: https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/
2530
+ 4. **Android UI 组件总览**: https://developer.android.com/develop/ui
2531
+ 5. **Material Design 3 规范**: https://m3.material.io/components
2532
+
2533
+ ---
2534
+
2535
+ *本文档基于 Android 14 / Material Design 3 和 HarmonyOS NEXT API 20/21 (6.0.0/6.0.1) 整理,具体 API 以官方最新文档为准。*