🚀一、开发卡片页面
HarmonyOS元服务卡片页面(Metaservice Card Page)是指在HarmonyOS系统中,用于展示元服务的页面界面。元服务是指一组提供特定功能或服务的组件,例如天气服务、音乐播放服务等。元服务卡片页面可以显示元服务的相关信息和操作选项,用户可以通过点击卡片页面上的按钮或交互元素来使用相关的元服务功能。元服务卡片页面提供了一种快速访问和使用元服务的方式,方便用户进行各种操作和任务。
🔎1.卡片页面能力说明
支持在卡片中使用的ArkTS能力:
🔎2.卡片使用动效能力
@Entry
@Component
struct AttrAnimationExample {@State rotateAngle: number = 0;build() {Column() {Button('change rotate angle').onClick(() => {this.rotateAngle = 90;}).margin(50).rotate({ angle: this.rotateAngle }).animation({curve: Curve.EaseOut,playMode: PlayMode.AlternateReverse})}.width('100%').margin({ top: 20 })}
}
🔎3.卡片使用自定义绘制能力
@Entry
@Component
struct Card {private canvasWidth: number = 0;private canvasHeight: number = 0;// 初始化CanvasRenderingContext2D和RenderingContextSettingsprivate settings: RenderingContextSettings = new RenderingContextSettings(true);private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);build() {Column() {Row() {Canvas(this.context).margin('5%').width('90%').height('90%').onReady(() => {console.info('[ArkTSCard] onReady for canvas draw content');// 在onReady回调中获取画布的实际宽和高this.canvasWidth = this.context.width;this.canvasHeight = this.context.height;// 绘制画布的背景this.context.fillStyle = 'rgba(203, 154, 126, 1.00)';this.context.fillRect(0, 0, this.canvasWidth, this.canvasHeight);// 在画布的中心绘制一个红色的圆this.context.beginPath();let radius = this.context.width / 3let circleX = this.context.width / 2let circleY = this.context.height / 2this.context.moveTo(circleX - radius, circleY);this.context.arc(circleX, circleY, radius, 2 * Math.PI, 0, true);this.context.closePath();this.context.fillStyle = 'red';this.context.fill();// 绘制笑脸的左眼let leftR = radius / 4let leftX = circleX - (radius / 2)let leftY = circleY - (radius / 3.5)this.context.beginPath();this.context.arc(leftX, leftY, leftR, 0, Math.PI, true);this.context.strokeStyle = '#ffff00'this.context.lineWidth = 10this.context.stroke()// 绘制笑脸的右眼let rightR = radius / 4let rightX = circleX + (radius / 2)let rightY = circleY - (radius / 3.5)this.context.beginPath();this.context.arc(rightX, rightY, rightR, 0, Math.PI, true);this.context.strokeStyle = '#ffff00'this.context.lineWidth = 10this.context.stroke()// 绘制笑脸的嘴巴let mouthR = radius / 2.5let mouthX = circleXlet mouthY = circleY + (radius / 3)this.context.beginPath();this.context.arc(mouthX, mouthY, mouthR, Math.PI, 0, true);this.context.strokeStyle = '#ffff00'this.context.lineWidth = 10this.context.stroke()})}}.height('100%').width('100%')}
}
🚀写在最后
- 如果你觉得这篇内容对你还蛮有帮助,我想邀请你帮我三个小忙:
- 点赞,转发,有你们的 『点赞和评论』,才是我创造的动力。
- 关注小编,同时可以期待后续文章ing🚀,不定期分享原创知识。
- 更多鸿蒙最新技术知识点,请关注作者博客:https://t.doruo.cn/14DjR1rEY