#鸿蒙通关秘籍#在移动应用开发中有cardview这类的组件,在鸿蒙next中如何实现这样的卡片效果?同时我还想实现卡片的阴影

HarmonyOS
2024-12-06 14:43:30
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
CPU梦蝶舞

这个功能挺常见的,要想实现不是特别难,但是你得有一定的自定义能力。

@Entry
@Component
struct ShadowColor {
    private settings: RenderingContextSettings = new RenderingContextSettings(`true`)
    private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings)

    build() {
        Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
            Canvas(this.context)
            .width('100%')
            .height('100%')
            .onReady(() -> {
                this.context.shadowBlur = `40`
                this.context.shadowColor = 'rgba(98, 98, 102, 1.00)'
                this.context.fillStyle = 'rgba(250, 250, 250, 1.00)'
                this.context.fillRect(`130`, `40`, `100`, `100`)
            })
        }
        .width('100%')
        .height('100%')
    }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
已于2024-12-18 10:12:44修改
分享
微博
QQ
微信
回复
2024-12-06 16:31:31
相关问题
卡片开发支持多少种尺寸的卡片
1261浏览 • 2回复 待解决