当前位置: 首页 > news >正文

鸿蒙 ArkUI 基础表单与卡片组件实训博客

鸿蒙 ArkUI 基础表单与卡片组件实训博客

一、实训介绍

本次实训使用 ArkTS 开发界面,练习 Column、Row 布局,Text、TextInput、Button、Image 组件样式配置,实现基础布局、简约登录、注册表单、多按钮登录、个人信息卡片共五组页面。

二、案例 1:基础居中布局 TextInputDemo

代码

ets

@Entry @Component struct TextlnputDemo{ build() { Column({space:30}) .width('100%') .height('100%') .justifyContent(FlexAlign.Center) .alignItems(HorizontalAlign.Center) } }

说明

页面通用基础骨架,创建全屏垂直居中布局容器。

三、案例 2:简约美化登录表单 StyleDemo

代码

ets

@Entry @Component struct StyleDemo{ build() { Column({space:20}){ TextInput({placeholder:"请输入账号"}) .width(320) .height(50) .backgroundColor(0xF8F8F8) .borderRadius(15) .padding({left:20}) TextInput({placeholder:"请输入密码"}) .width(320) .height(50) .backgroundColor(0xF8F8F8) .borderRadius(15) .padding({left:20}) Button("登录") .width(320) .height(50) .borderRadius(12) .backgroundColor(0x007dff) .fontSize(18) .fontColor(Color.White) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) .alignItems(HorizontalAlign.Center) .padding(20) } }

说明

简易登录表单,对输入框、按钮做圆角、底色美化,搭建简洁登录界面。

四、案例 3:用户注册页面 TextDemo

代码

ets

@Entry @Component struct TextDemo { build() { Column({space:30}) { Text('用户注册') .fontSize(38) .fontWeight(FontWeight.Bolder) .margin({bottom:20}) TextInput({placeholder:"请输入学号"}) .width(320) .height(60) .backgroundColor(0xf5f5f5) .fontSize(20) .borderRadius(10) TextInput({placeholder:"请输入密码"}) .type(InputType.Password) .width(320) .height(60) .backgroundColor(0xf5f5f5) .fontSize(20) .borderRadius(10) TextInput({placeholder:"请输入手机号码"}) .width(320) .height(60) .backgroundColor(0xf5f5f5) .fontSize(20) .borderRadius(10) Button('注册') .height(50) .width(200) .fontSize(25) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) .alignItems(HorizontalAlign.Center) } }

说明

完整注册表单,包含学号、密码、手机号三项输入,使用密码密文输入模式,搭配注册提交按钮。

五、案例 4:多按钮登录页面 ButtonDemo1

代码

ets

@Entry @Component struct ButtonDemo1 { build() { Column({ space: 30 }) { Text('用户登录') .fontSize(38) .fontWeight(FontWeight.Bolder) .margin({ bottom: 20 }) TextInput({ placeholder: "请输入学号/手机号码" }) .width(320) .height(60) .backgroundColor(0xf5f5f5) .fontSize(40) .borderRadius(10) TextInput({ placeholder: "请输入密码" }) .type(InputType.Password) .width(320) .height(60) .backgroundColor(0xf5f5f5) .fontSize(40) .borderRadius(10) Button("确认") .width(300) .height(50) .backgroundColor(0x007DFF) .fontSize(20) .borderRadius(18) Row({ space: 25 }) { Button("取消操作") .width(140) .height(50) .backgroundColor(0x999999) .fontSize(20) .borderRadius(18) Button("立即注册") .width(140) .height(50) .backgroundColor(0xf53f3f) .fontSize(20) .borderRadius(18) } } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) .alignItems(HorizontalAlign.Center) } }

说明

多功能按钮登录页,通过 Row 横向排列取消、注册按钮,使用不同颜色区分按钮功能。

六、案例 5:个人信息卡片 card

代码

ets

@Entry @Component struct card { build() { Column({ space: 20 }) { Text("个人信息中心") .fontSize(22) .fontWeight(FontWeight.Bold) .width('100%') .textAlign(TextAlign.Center) .margin({ bottom: 20 }) Column({ space: 20 }) { Row({ space: 20 }) { Image($r('app.media.cover')) .width(80) .height(80) .borderRadius(40) Column({ space: 10 }) { Text("鸿蒙应用开发者:张三") .fontSize(16) Text("计算机应用工程系") .fontSize(16) } } .width('100%') .justifyContent(FlexAlign.Start) .alignItems(VerticalAlign.Center) Row({ space: 15 }) { Button("编辑资料") .width(140) .height(40) .borderRadius(8) Button("查看详情") .width(140) .height(40) .borderRadius(8) } .width('100%') .justifyContent(FlexAlign.Center) } .width('100%') .padding(20) .backgroundColor(0xF0F0F0) .borderRadius(12) } .width('100%') .height('100%') .padding(15) .justifyContent(FlexAlign.Center) .alignItems(HorizontalAlign.Center) } }

说明

卡片式个人信息页面,结合圆形头像、文字信息、功能按钮,使用嵌套布局实现卡片容器效果。

七、实训总结

本次案例练习了垂直、水平两种基础布局,掌握文本、输入框、按钮、图片组件基础样式美化,实现项目中常见的登录、注册表单以及个人信息卡片页面。

http://www.jsqmd.com/news/1075977/

相关文章:

  • Tacent View:游戏纹理与专业图像处理的现代化解决方案
  • Topit:让你的Mac窗口永远在最前方,工作效率提升300%的秘密武器
  • 生产级机器学习服务落地:ONNX+Triton实战指南
  • 决策树实战:用可解释规则简化复杂业务选择
  • GitHub Desktop中文汉化完整指南:5分钟告别英文困扰
  • 2026保姆级Word文档压缩大小教程,图文图片压缩、清理隐藏数据、另存压缩全方法
  • TestDisk PhotoRec:免费开源的数据恢复终极解决方案
  • 澳大利亚海牙认证在哪里办理?澳洲海牙认证办理流程是什么?
  • GEO 贴牌怎么做 2026 选型攻略,依托实测案例规避贴牌套路
  • HarmonyOS7 列表流实战 ----别急着改代码,先把示例工程真正跑通
  • Beyond Compare 5密钥生成完整指南:从逆向分析到激活实战
  • o3-mini驱动的端到端ML工程化实战:从推理协同到低摩擦部署
  • 墨香润夏:临汾夏令营里的文脉与成长
  • TriliumNext × WechatSync Publisher Bridge 同时同步多篇文章
  • Hadoop练习卷大题部分简洁答案
  • OpCore Simplify:三步实现专业级黑苹果EFI配置
  • AI赋能传统行业:从生产到营销的生存重构与收藏指南
  • 2026前端开发新范式:用Gemini镜像站解决React/Vue组件设计、状态管理与性能瓶颈
  • 如何将iPhone照片备份到电脑/iCloud/iTunes
  • 面试官:为什么你的GEO内容“看起来正常但就是不被引用”?我用一套日志系统抓到了真凶
  • MuleSoft企业级AI编排实战:LLM与ERP/CRM安全集成
  • AI进化论:数据环境与软件基因的协同选择机制
  • OpCore Simplify:3步完成黑苹果配置的终极简单指南
  • 白嫖 8 元无门槛券!千问新人福利保姆级教程
  • 企业注销登报公示多少天?可以去哪里办?
  • 用WBS任务拆解,彻底解决项目进度模糊、任务遗漏难题
  • 联发科设备终极掌控指南:3步学会使用MTKClient刷机工具
  • 3个必学技巧:用G-Helper彻底释放ROG Ally掌机潜能
  • RKC RCB-28-4D温度控制器
  • Kimi LeetCode 3373. 连接两棵树后最大目标节点数目 II Java实现