【综合案例】使用DevEco Studio编写人气卡片

效果展示

知识点

绝对定位

作用:控制组件位置,可以实现层叠效果

特点:

  1. 参照 父组件左上角 进行偏移
  2. 绝对定位后的组件 不再占用自身原有位置

语法:.position(位置对象)

参数:{ x: 水平偏移量 , y: 垂直偏移量}

zIndex层级

作用:调整组件层级

语法:.zIndex(数字)

参数:取值为整数数字,取值越大,显示层级越高

代码展示

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  build() {
    Column() {
      Column() {
        Text("VIP")
          .position({
            x: 0,
            y: 0
          })
          .zIndex(1)
          .width(70)
          .height(40)
          .textAlign(TextAlign.Center)
          .fontSize(20)
          .fontWeight(700)
          .border({
            width: 5,
            color: "#F8EA87"
          })
          .borderRadius({
            topLeft: 20,
            bottomRight: 20
          })
          .fontColor("#F8EA87")
          .backgroundColor("#F1932D")
        Image($r("app.media.position_moco"))
          .width('99%')
          .borderRadius(20)
        Row({ space: 20 }) {
          Image($r("app.media.position_earphone"))
            .padding(5)
            .width(30)
            .borderRadius(15)
            .fillColor("#fff")
            .backgroundColor("#0AC1EF")
          Text("飞狗MOCO")
            .fontSize(24)
            .fontWeight(700)
        }
        .padding({
          left: 20
        })
        .margin({
          top: 10,
          bottom: 10
        })
        .width("100%")
      }
      .width(300)
      .backgroundColor("#fff")
    }
    .padding(20)
    .width("100%")
    .height("100%")
    .linearGradient({
      angle: 135, // 设置颜色渐变起始角度为顺时针方向45°
      colors: [
        [0xceeff2, 0.0],
        [0xf2e0de, 0.4],
        [0xFFFFFF, 0.8],
      ]
    })
  }
}

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值