首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

鸿蒙HarmonyOS实战-Stage模型(开发卡片页面)

  • 25-02-22 03:40
  • 3868
  • 5654
blog.csdn.net

 一、开发卡片页面

HarmonyOS元服务卡片页面(Metaservice Card Page)是指在HarmonyOS系统中,用于展示元服务的页面界面。元服务是指一组提供特定功能或服务的组件,例如天气服务、音乐播放服务等。元服务卡片页面可以显示元服务的相关信息和操作选项,用户可以通过点击卡片页面上的按钮或交互元素来使用相关的元服务功能。元服务卡片页面提供了一种快速访问和使用元服务的方式,方便用户进行各种操作和任务。

1.卡片页面能力说明

支持在卡片中使用的ArkTS能力:

类别组件/对象通用属性事件其他
属性动画
显式动画
组件内转场
像素单位
组件Blank组件Background通用属性点击事件
Button组件BackgroundBlurStyle通用属性挂载卸载事件
Checkbox组件BorderImage通用属性组件生命周期
CheckboxGroup组件Border通用属性状态管理
DataPanel组件ComponentId通用属性
Divider组件Enable通用属性
Gauge组件FlexLayout通用属性
Image组件GradientColor通用属性
LoadingProgress组件ImageEffect通用属性
Marquee组件LayoutConstraints通用属性
Progress组件Location通用属性
Qrcode组件Opacity通用属性
Radio组件Overlay通用属性
Rating组件PolymorphicStyle通用属性
Slider组件SharpClipping通用属性
Span组件Size通用属性
Text组件Touch-target通用属性
Toggle组件Transformation通用属性
绘制上下文对象Canvas绘制上下文对象Visibility通用属性
绘制组件Canvas组件ZOrder通用属性
绘制组件对象渐变对象
ImageBitmap对象
ImageData对象
Path2D对象
容器组件Badge容器组件
Column容器组件
Counter容器组件
Flex容器组件
GridCol容器组件
GridRow容器组件
List容器组件
ListItem容器组件
RelativeContainer容器组件
Row容器组件
Stack容器组件
绘制组件Circle绘制组件
Ellipse绘制组件
Line绘制组件
Path绘制组件
Polygon绘制组件
Polyline绘制组件
Rect绘制组件
Shape绘制组件

2.卡片使用动效能力

名称参数说明限制描述
duration动画播放时长限制最长的动效播放时长为1秒,当设置大于1秒的时间时,动效时长仍为1秒。
tempo动画播放速度卡片中禁止设置此参数,使用默认值1。
delay动画延迟执行的时长卡片中禁止设置此参数,使用默认值0。
iterations动画播放次数卡片中禁止设置此参数,使用默认值1。
  1. @Entry
  2. @Component
  3. struct AttrAnimationExample {
  4. @State rotateAngle: number = 0;
  5. build() {
  6. Column() {
  7. Button('change rotate angle')
  8. .onClick(() => {
  9. this.rotateAngle = 90;
  10. })
  11. .margin(50)
  12. .rotate({ angle: this.rotateAngle })
  13. .animation({
  14. curve: Curve.EaseOut,
  15. playMode: PlayMode.AlternateReverse
  16. })
  17. }.width('100%').margin({ top: 20 })
  18. }
  19. }

在这里插入图片描述

3.卡片使用自定义绘制能力

  1. @Entry
  2. @Component
  3. struct Card {
  4. private canvasWidth: number = 0;
  5. private canvasHeight: number = 0;
  6. // 初始化CanvasRenderingContext2D和RenderingContextSettings
  7. private settings: RenderingContextSettings = new RenderingContextSettings(true);
  8. private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
  9. build() {
  10. Column() {
  11. Row() {
  12. Canvas(this.context)
  13. .margin('5%')
  14. .width('90%')
  15. .height('90%')
  16. .onReady(() => {
  17. console.info('[ArkTSCard] onReady for canvas draw content');
  18. // 在onReady回调中获取画布的实际宽和高
  19. this.canvasWidth = this.context.width;
  20. this.canvasHeight = this.context.height;
  21. // 绘制画布的背景
  22. this.context.fillStyle = 'rgba(203, 154, 126, 1.00)';
  23. this.context.fillRect(0, 0, this.canvasWidth, this.canvasHeight);
  24. // 在画布的中心绘制一个红色的圆
  25. this.context.beginPath();
  26. let radius = this.context.width / 3
  27. let circleX = this.context.width / 2
  28. let circleY = this.context.height / 2
  29. this.context.moveTo(circleX - radius, circleY);
  30. this.context.arc(circleX, circleY, radius, 2 * Math.PI, 0, true);
  31. this.context.closePath();
  32. this.context.fillStyle = 'red';
  33. this.context.fill();
  34. // 绘制笑脸的左眼
  35. let leftR = radius / 4
  36. let leftX = circleX - (radius / 2)
  37. let leftY = circleY - (radius / 3.5)
  38. this.context.beginPath();
  39. this.context.arc(leftX, leftY, leftR, 0, Math.PI, true);
  40. this.context.strokeStyle = '#ffff00'
  41. this.context.lineWidth = 10
  42. this.context.stroke()
  43. // 绘制笑脸的右眼
  44. let rightR = radius / 4
  45. let rightX = circleX + (radius / 2)
  46. let rightY = circleY - (radius / 3.5)
  47. this.context.beginPath();
  48. this.context.arc(rightX, rightY, rightR, 0, Math.PI, true);
  49. this.context.strokeStyle = '#ffff00'
  50. this.context.lineWidth = 10
  51. this.context.stroke()
  52. // 绘制笑脸的嘴巴
  53. let mouthR = radius / 2.5
  54. let mouthX = circleX
  55. let mouthY = circleY + (radius / 3)
  56. this.context.beginPath();
  57. this.context.arc(mouthX, mouthY, mouthR, Math.PI, 0, true);
  58. this.context.strokeStyle = '#ffff00'
  59. this.context.lineWidth = 10
  60. this.context.stroke()
  61. })
  62. }
  63. }.height('100%').width('100%')
  64. }
  65. }

在这里插入图片描述

 ?写在最后

  • 如果你觉得这篇内容对你还蛮有帮助,我想邀请你帮我三个小忙:
  • 点赞,转发,有你们的 『点赞和评论』,才是我创造的动力。
  • 关注小编,同时可以期待后续文章ing?,不定期分享原创知识。
  • 想要获取更多完整鸿蒙最新VIP学习资料,请点击→全套鸿蒙HarmonyOS学习资料
  • 或者关注小编后私信回复【666】也可获取资料哦~~

最新鸿蒙Next全套学习资料请扫码
微信名片
注:本文转载自blog.csdn.net的蜀道山QAQ的文章"https://blog.csdn.net/shudaoshanQAQ/article/details/135479911"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2025 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top