// 使用硬件加速的动画实现 Button("查看解析") .onClick(() => { animateTo({ duration: 300, curve: Curve.EaseOut, onFinish: () => { showAnalysis() } }, () => { this.rotateAngle = 180 }) }) .rotate({ angle: this.rotateAngle })
@Component struct AdaptiveButton { @Prop label: string @Prop size: 'small' | 'medium' | 'large' @Prop buttonType: 'primary' | 'secondary' build() { Button(this.label) .fontSize(this.getFontSize()) .padding(this.getPadding()) .backgroundColor(this.getBackgroundColor()) } private getFontSize(): number { switch (this.size) { case 'small': return 12 case 'medium': return 14 case 'large': return 16 } } }
GridContainer({ columns: { sm: 1, // 小屏设备1列 md: 2, // 中屏设备2列 lg: 3 // 大屏设备3列 }, gutter: 12 }) { ForEach(this.questions, (item: Question) => { QuestionCard({ data: item }) }) } .onAreaChange((newArea) => { this.currentDevice = getDeviceType(newArea.width) })
// resources/base/element/string.json { "question_font_size": { "phone": "16fp", "tablet": "18fp", "tv": "24fp" } }
提交